I have three tables:
CREATE TABLE Playlist
(`id` int, `name` varchar(90))
;
INSERT INTO Playlist
(`id`, `name`)
VALUES
(1, 'Playlist_1'),
(100, 'EmptyPlaylist'),
(111, 'Playlist_222'),
(1001, 'Playlist_4')
;
CREATE TABLE PlaylistItem
(`id` int, `trackID` int, `playlistID` int)
;
INSERT INTO PlaylistItem
(`id`, `trackID`, `playlistID`)
VALUES
(3, 2, 1),
(32, 22, 1),
(321, 222, 1),
(333, 222, 3),
(333, 2, 3),
(303, 200, 1001)
;
CREATE TABLE Track
(`id` int, `title` varchar(300))
;
INSERT INTO Track
(`id`, `title`)
VALUES
(2, 'Foo'),
(22, 'Bar'),
(200, 'Only_In_Playlist_4_Which_Is_Not_Included_In_the_Query'),
(222, 'Byy'),
(21, 'NotInAnyPlaylist'),
(20000, 'NotInAnyPlaylist_2')
;
Each Playlist
contains multiple PlaylistItem
, which contain one Track
. My goal is to provide an array of Playlist IDs
and get all Tracks
inside those playlist (not only their IDs).
However, I do not know how to access subitems from a query. I used joins but they merge the keys and I only want to get the tracks without the keys from other tables. I could select just the keys from Track
with a join, but my Track
table has over 100 keys and they could change.
Desired outcome :
id | title |
---|---|
2 | Foo |
22 | Bar |
222 | Byy |
I get track IDs now with this:
SELECT
trackID
FROM
PlaylistItem
WHERE
playlistID in ('1', '4') -- Here comes the array of IDs, for the example I want '1' and '4'