PDA

View Full Version : Help me with a query pls


neverstop
10-14-2009, 06:28 PM
HI everyone.

I am trying to make a list of users that have received the most reputation comments. That is not the most points (or least points) but how many total comments ocmbined they have received.

I dont need help with the php just the query has stumped me.

The table 'reputation' has the following fields:

reputationid postid userid reputation whoadded reason dateline



The field in question is 'userid'

Thanks in advance

Adrian Schneider
10-14-2009, 06:47 PM
Try this... untested, as I have no data to test this on.

SELECT user.userid
, user.username
, counts.comments
FROM ( SELECT userid
, COUNT(*) AS comments
FROM reputation
WHERE reason IS NOT NULL
GROUP
BY userid ) AS counts
INNER
JOIN user
ON user.userid = counts.userid
ORDER
BY counts.comments DESC
LIMIT 10;

neverstop
10-14-2009, 07:14 PM
Awesome, you even added the username for me!

Seems to work flawlessly Adrian, thank you so much man!