Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •