I'm working on a site that lists music. I have two tables, one called music_artists and one called music_pieces.
music_artists has id and name. id is a unique number and name is the "user friendly" artist name.
music_pieces has id, artistid, title. id is a unique number, artistid corresponds to id in music_artists which says which artist wrote the piece, and title is the "user friendly" title.
I would like to generate an index that lists all the artists and the number of pieces they have in the database. So I would like it to look like this:
-Air (6)
-Hayden (4)
-Yann Tiersen (8)
etc etc.
Is there a way I can accomplish this with a single SQL query?
I suspect I need to JOIN and COUNT things, but I only have a basic SELECT/UPDATE/DELETE knowledge of MySQL.
music_artists has id and name. id is a unique number and name is the "user friendly" artist name.
music_pieces has id, artistid, title. id is a unique number, artistid corresponds to id in music_artists which says which artist wrote the piece, and title is the "user friendly" title.
I would like to generate an index that lists all the artists and the number of pieces they have in the database. So I would like it to look like this:
-Air (6)
-Hayden (4)
-Yann Tiersen (8)
etc etc.
Is there a way I can accomplish this with a single SQL query?
I suspect I need to JOIN and COUNT things, but I only have a basic SELECT/UPDATE/DELETE knowledge of MySQL.