CLiown
CLiown

Reputation: 13843

Find top contributers from DB

Each post that gets created on my site get stored in a database table, inside that table is a column which lists the users username.

I'd like to find the top 10 contributers to my site, how can I count all the posts create by all users and then display the top 10 contributers in a list.

Table name: posts Table column: username

Each post has a username entry.

Upvotes: 1

Views: 77

Answers (2)

Capt Otis
Capt Otis

Reputation: 1260

Why not have a post count field? I assume this is some sort of forum, and users like to know their post count. Then you just select the top posters.

Then run something like...

 SELECT username FROM tablename ORDER BY postcount DESC limit 10

Upvotes: 2

Jonathan Fingland
Jonathan Fingland

Reputation: 57167

 SELECT count(username) a,username from posts group by username order by a desc limit 10

Upvotes: 6

Related Questions