I have 3 tables: musiccollection: id (pk), title, artist.. etc etc musiccollection_playlist: mcpid (pk), playlistid (fk:playlist.playlistid), trackid(fk:musiccollection.id) playlist: playlistid (pk), playlistname
I want to display the whole rows in musiccollection as shown in the musiccollection_playlist table respective foreign key.
ex. in musiccollection table
id title artist
1 song1 artist1
2 song2 artist2
3 song3 artist3
4 song4 artist4
5 song5 artist5
ex. in playlist table
playlistid playlistname
1 playlist1
2 playlist2
ex. in musiccollection_playlist
mcpid playlistid trackid
1 1 2
2 1 4
3 1 5
Now I want to display the data in musiccollection_playlist WHERE playlistid is 1 (general example). However I want the returned data to be the actual rows in music_collection table where the id's chosen would be 2,4,5.
I am attempting to write the query:
SELECT * FROM musiccollection as a, musiccollection_playlist as b WHERE a.id IN (SELECT trackid FROM musiccollection_playlist) AND b.playlistid = '1'
I have to be reasoning something out wrongly or I have something wrong in the query. How can I fix this to achieve what I want? i.e. display the whole row identified by the trackid in musiccollection_playlist.
In reality I can do something like:
SELECT trackid FROM musiccollection_playlist WHERE playlistid = '1'
The trackid then has to reference from the musiccollection table.
What do you suggest?