I’m new at this so I’m having a hard time solving this problem, I’ve searched high and low but I can’t seem to find an answer.
This is how my tables look:
Table artist
| Columns | Constraints |
|---|---|
| Artist_id | PK |
| Name | - |
Table song
| Columns | Constraints |
|---|---|
| Song_id | PK |
| Title | - |
| artist_id | FK |
| co_artist_id | FK |
Table top_list
| Columns | Constraints |
|---|---|
| Id | PK FK |
I’ve made two foreign keys in the song table to the same primary key (artist_id). And also made a foreign key in top_list with song_id
My query is:
SELECT a.name Artist, COUNT(*)
FROM top_list tl
INNER JOIN song s ON tl.id = s.song_id
INNER JOIN artist a ON s.artist_id = a.artist_id
GROUP BY a.name
ORDER BY COUNT(*) DESC;
LIMIT 1;
I want to count both the artist and the co-artist. ATM it only counts song.artist_id and not song.co_artist_id




