SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to SORT results made with COUNT?

    Hello,

    I have to choose artists with biggest number of songs from DB.

    To count the number of songs for each artist I use this query:

    PHP Code:
    SELECT artisCOUNT(songFROM lyric GROUP BY artis LIMIT 0,100
    I wonder is it possible to sort results by number of songs in the same MySQL query? Or I should use other methods to sort results?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    of course it's possible
    Code:
    SELECT artis
         , COUNT(*) AS songs  FROM lyric 
    GROUP 
        BY artis 
    ORDER 
        BY songs DESC LIMIT 0,100
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Mar 2004
    Posts
    639
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Niiice

    Thanks a LOT.


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
  •