Lesson 464, Intermediate Joins in SQL, Combining Multiple Joins with Subqueries
Screen Link:
My Code:
SELECT
ta.album_title album,
ta.artist_name artist,
COUNT(*) tracks_purchased
FROM invoice_line il
INNER JOIN (
SELECT
t.track_id,
al.title album_title,
ar.name artist_name
FROM track t
INNER JOIN album al ON al.album_id = t.album_id
INNER JOIN artist ar ON ar.artist_id = al.artist_id
) ta
ON ta.track_id = il.track_id
GROUP BY 1, 2
ORDER BY 3 DESC LIMIT 5;
-- SELECT
-- ta.title album,
-- ta.name artist,
-- COUNT(*) track_purchased
-- FROM invoice_line il
-- INNER JOIN (
-- SELECT
-- t.track_id,
-- al.title,
-- ar.name
-- FROM track t
-- INNER JOIN album al ON al.album_id = t.album_id
-- INNER JOIN artist ar ON ar.artist_id = al.artist_id
-- ) ta
-- ON ta.track_id = il.track_id
-- GROUP BY 1, 2
-- ORDER BY 3 DESC
-- LIMIT 5
-- ;
What I expected to happen:
I would think these two SQL queries would have the same results but they don’t.
What actually happened:
The outputted table is off by one line
Replace this line with the output/error
Should these queries have the same output or am I missing something?