Enquiry regarding how sequence of JOINS in SQL

Screen Link:

The answer joined the respective datasources/dataframes in this manner:

     FROM playlist p
     LEFT JOIN playlist_track pt ON pt.playlist_id = p.playlist_id
     LEFT JOIN track t ON t.track_id = pt.track_id
    )

Question:
Hi everyone! How do you know that we have to start from playlist> playlist_track> track? At first, what how i joined them together was track> playlist_track> playlist, which was wrong. Also, why do we use LEFT JOIN in this screen? The author did not explicitly mention to use LEFT JOIN, so in actual fact i can use INNER JOIN.

Thanks!

1 Like

Hi @lauratangwt,

Actually, it’s implied in the task that we have to use only LEFT JOIN starting from playlist ():

Create a query that shows summary data for every playlist in the Chinook database.

It means that we have to preserve every playlist name, including those with no tracks available. Tecnically, it exactly means using LEFT JOIN on playlist.

About the order “playlist > playlist_track > track”, well, exactly because of that :slightly_smiling_face: Because we have to preserve all items of playlist and then add to them 'number_of_tracks' and 'length_seconds', obtained from playlist_track and track tables correspondingly.

Hope it was useful.

2 Likes

@lauratangwt

Kindly see this and this.

2 Likes