I am trying to construct a MySQL query that will allow me to pull the song title of a track in the database that has a genre of both Pop and Electronic.
+----------------------------------------------------+
TABLE: SONG
+----------------------------------------------------+
song_id | title |
1 | song name |
+----------------------------------------------------+
TABLE: GENRE
+----------------------------------------------------+
genre_id | name |
1 | Pop |
2 | Electronic |
+----------------------------------------------------+
TABLE: SONG_GENRE
+----------------------------------------------------+
genre_id | song_id |
1 | 1 |
2 | 1 |
This SQL doesn't work, as it is obviously never going to return both a genre_id of 1 and 2 but this is where I am stuck.
SELECT DISTINCT song.song_id, song.title
FROM song
LEFT JOIN song_genre ON song_genre.song_id = song.song_id
LEFT JOIN genre ON genre.genre_id = song_genre.genre_id
WHERE genre.genre_id ='1'
AND genre.genre_id='2'
If somebody could point me in the right direction I would be most greatful!