I know this is easy, but it drives me crazy ...
I have a user table, comment table, and picture table.
I want the list of the top 10 users to be based on materials (all their comments and their photos).
What is it.
Shame on me.
UPDATE: Based on Ed.
here is my setup:
- user table (user_id, username)
- image table (img_id, submittedby_id = users.user_id)
- comment table (id, submittedby_id = users.user_id)
and final request:
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;
source share