SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: MySQL count()

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL count()

    I want to list the person that shows up the most in order of count

    for example this is the table

    id from item_id to
    1 bob 4 sarah
    2 mike 2 tim
    3 bob 1 evan
    4 tom 4 sarah



    I want it to display that

    Sarah has two # 4's
    then it would go in order
    So tim and evan both have one 2 and 3

    Is this possible...

    Thanks so much, and sorry if this makes no sense at all

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    one of these two will give you the result you want:
    Code:
    select `to`
         , count(*) as theCount
      from theTable
    group
        by `to`
    order
        by theCount
    Code:
    select `to`
         , item_id
         , count(*) as theCount
      from theTable
    group
        by `to`
         , item_id
    order
        by theCount

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That worked great! Thanks!


Bookmarks

Posting Permissions

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