October 23rd, 2012, 01:56 AM
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:
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
select title, label from album;
October 23rd, 2012, 02:56 AM
I now have this
but is it even possible to sort them both ascending?
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;
October 23rd, 2012, 06:43 AM
what happened when you tested it?
Originally Posted by newmz89
October 23rd, 2012, 07:37 AM
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.
Originally Posted by r937
October 23rd, 2012, 07:53 AM
You wouldn't want to order by title but order by `number of albums` which is the count of titles from each label.