SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to order the displayed results, by the highest number at the top,, for example


    if i am getting names out of a db, and there are 32 erics, 20 johns, 5 peters and 89 bills

    i want it to display in this order

    89 bills
    32 eric
    20 john
    5 peters

    how would i go about doing this?
    ___________________________________

    << Footer under construction >>

  2. #2
    SitePoint Addict Drinky's Avatar
    Join Date
    Jan 2001
    Location
    England
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT DISTINCT names, COUNT(names) AS num FROM table GROUP BY names ORDER BY num DESC
    Drinky

  3. #3
    SitePoint Addict Drinky's Avatar
    Join Date
    Jan 2001
    Location
    England
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Although the output will look like this

    bills 89
    eric 32
    john 20
    peters 5

    small price to pay tho :O)
    Drinky

  4. #4
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    works like a charm!!!

    thanks Drinky!!
    ___________________________________

    << Footer under construction >>

  5. #5
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey no fare.. i just answered this question a minute ago .. haha
    cogito, ergo sum

  6. #6
    SitePoint Addict Drinky's Avatar
    Join Date
    Jan 2001
    Location
    England
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I win! I win!

    Drinky


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
  •