sql question

They have: 87 posts

Joined: Dec 2001

I have a script that i need to find out the top posters.

I need to somehow find a way to select the highest amount of posts. Its really hard to explain, i have the table set up with a field called "dsub", i need to know how to select the most common user id in that field. If you know how to do this, please let me know.

http://www.newbie-developer.com - Newbie web-developer community.

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

Try this:

SELECT TOP 5 dsub
FROM MyUserTable
GROUP BY dsub
ORDER BY COUNT(dsub) DESC

That will return the top 5 user ids. You'll have to modify it to work with your database tables and fields.

PJ | Are we there yet?
pjboettcher.com

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

and for mySQL:

SELECT dsub
FROM MyUserTable
GROUP BY dsub
ORDER BY COUNT(dsub) DESC
LIMIT 5

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.