I have two tables, users table that contains all the users in my system and other table called action with all the actions done by the users in my system, what I want to get is a query where i can count the actions by the user and if I don't have any action for one user get 0.
My two tables:
Users Table:
Name Place
----------------------
James Supermarket
Alex Bank
Ignatius BookShop
Action table:
Name Action
--------------------
James Buy
James Buy
Alex Complaint
Alex Buy
Alex Buy
I want something like this:
Name Transactions Place
-------------------------------
James 2 Supermarket
Alex 3 Bank
Ignatius 0 BookShop
I tryied with:
SELECT users.name,
(SELECT Count(action.name)
FROM action,
users
WHERE action.name = users.name
GROUP BY action.name)
users.place
FROM
action,
users
WHERE action.name = users.name
But is always giving me this error:
ERROR: more than one row returned by a subquery used as an expression SQL state: 21000
Any idea about how to do it?