I know this is an easy one, but it's driving me nuts...
I have a users table, comments table, and pictures table.
I want a list of the top 10 users based on submissions (total of their comments and their submitted photos).
That's it.
Shame me.
UPDATE: based on Ed's answer.
here's my setup:
- users table (user_id, username)
- images table (img_id, submittedby_id = users.user_id)
- comments table (id, submittedby_id = users.user_id)
and the final query:
select submittedby_id, sum(total)
from
(select submittedby_id, count(img_id) as total from
images group by submittedby_id
union
select submittedby_id, count(id) as total from
comments group by submittedby_id
) as x
group by submittedby_id
order by sum(total) desc limit 10;