My current query:
SELECT *
FROM `reported_users`
GROUP BY `reported_user`
ORDER BY ???
I have a reported_users table. When users on my site report another user for breaking the rules the reported user is inserted as a row in this table. So the same user can have multiple rows in the table. To make sure I get each user only once I am using GROUP BY on the reported_user field. But how can I ORDER BY users who were reported the most to least. So if the table looks like this:
reported_user | reporter
---------------------------
Joe | Bob
Jake | Nady
Lisa | Tim
Joe | Jim
Joe | Foo
Lisa | Bar
the query should return:
Joe (3)
Lisa (2)
Jake (1)
I would also like to return how many times each user was reported. How can this be done?
1 Answer