https://app.dataquest.io/m/190/building-and-organizing-complex-queries/3/the-with-clause
WITH track_info AS
(SELECT playlist.playlist_id,
playlist.name playlist_name,
track.name,
(track.milliseconds/1000) length_seconds
FROM track
LEFT JOIN playlist_track ON playlist_track.track_id = track.track_id
LEFT JOIN playlist ON playlist.playlist_id = playlist_track.playlist_id)
SELECT playlist_id, playlist_name, COUNT(name) number_of_tracks, SUM(length_seconds)length_seconds
FROM track_info
GROUP BY playlist_id,playlist_name
ORDER BY playlist_id
I was continuously getting wrong answer with my code. I check the answer and the only difference I can locate is the order with which I have written my JOIN statement. I the code above track is joined to playlist_track which is then joined to playlist
How would I figure out which table to place first?