Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-25-2013, 08:25 PM   PM User | #1
prizegrand
New Coder

 
Join Date: Dec 2011
Posts: 32
Thanks: 2
Thanked 0 Times in 0 Posts
prizegrand is an unknown quantity at this point
Question mysql query help with counting!

Hi,

I have a simple problem, but i don't know how to fix it or what it is called. I've searched on the internet and everything, but my approach is probably wrong since i have been using SELECT user, SUM...

Anyways, i need a query that can SELECT all the data from the database, and list it by outputting the top 10 users (each user per row) from the database. Clarifying from what i just said, here is how the table would look:

USER
Bob
Bob
Bob
Sarah
Sarah
George

So essentially, i want to select the user from the database that has the most occurrences.
What would the query be for me to select the user that has the most occurances and list it from that order descending?
The output should be:

1. Bob
2. Sarah
3. George

(kind of like a contest)

Each name is on a seperate row in the table. The user that has the most rows should be first place and so on.

Can anyone help please?

Thanks!
-George
prizegrand is offline   Reply With Quote
Old 01-25-2013, 08:47 PM   PM User | #2
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
Here is one that I use.
PHP Code:
SELECT count(ticket_number) as countticket_user FROM tickets group by ticket_user order by count DESC LIMIT 10 
__________________
If you can't stand behind your troops, feel free to stand in front of them
Semper Fidelis
jimhill is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:10 AM.


Advertisement
Log in to turn off these ads.