Let's say I have three tables (with the columns in each):
USERS: id, name, account_id
ACCOUNTS: id, name
EVENTS: event_id, user_id, date
And I want to get the total count of events from EVENTS for each user, within a date range, along with the user's name and account name.
I can use GROUP BY to group the results by user_id, but how do I then join that to the users and accounts to get that info in each row? I'm trying to get an output like:
+-------+---------------------+--------+
| name | account_name |count(*)|
+-------+---------------------+--------+
| Joe | XYZ, Inc. | 10 |
| Bob | Vandalay Industries | 21 |
| Mary | Account Name Here | 32 |
+-------+---------------------+--------+
where the third column is the total number of events in the EVENTS table for that user_id in a specified date range.
Sorry, I can never get the hang of joins like this..