Screen Link:
https://app.dataquest.io/m/464/intermediate-joins-in-sql/4/combining-multiple-joins-with-subqueries
My Code:
select
a.title as album,
s.name as artist,
sum(i.quantity) as tracks_purchased
from
invoice_line i
join track t on
i.track_id = t.track_id
join album a on
t.album_id = a.album_id
join artist s on
a.artist_id = s.artist_id
group by
a.title,
s.name
order by
sum(i.quantity) DESC
limit 5
What I expected to happen:
The code to return the correct results.
What actually happened:
The code returned the correct results.
Replace this line with the output/error
The “solution” code specifically joins the invoice_line table to a subquery that joins the track table, artist table, and album table. What is the reason behind using the additional subquery? Why not use the approach outlined in my code and simply inner join the four tables together? Thanks!