#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    SQL count query help


    Okay the query I have been asked is to

    "How many albums have been released by each label?
    Do not display any NULL values.
    Sort the ouput in ascending order of number of albums, and ascending order of label."



    So far I have:

    Code:
    select title, label from album;
    Which shows both the title of the album and the label its produced by, but what count function do I use and how to I implement it so I can have how many albums have been released by each label? Thank you
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    I now have this

    Code:
    select label AS "RECORD LABEL", count(title) AS "NUMBER OF ALBUMS" from album WHERE label IS NOT NULL group by label ORDER BY label ASC, title ASC;
    but is it even possible to sort them both ascending?
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Originally Posted by newmz89
    but is it even possible to sort them both ascending?
    what happened when you tested it?

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by r937
    what happened when you tested it?

    I actually worked it out in the end. So its all good. I no doubt will have to ask for some more help later though.
  8. #5
  9. Hockey face
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    St. Catharines, Canada
    Posts
    8,147
    Rep Power
    1317
    You wouldn't want to order by title but order by `number of albums` which is the count of titles from each label.

IMN logo majestic logo threadwatch logo seochat tools logo