LIMITED TIME OFFER: 50% OFF OF PREMIUM WITH OUR ANNUAL PLAN (THAT'S $294 IN SAVINGS).
GET OFFER

Solution to Joining More Than 3 Tables - Not Correct Number of Rows

Screen Link:
https://app.dataquest.io/m/189/intermediate-joins-in-sql/3/joining-more-than-three-tables

My Code:

SELECT
    il.track_id,
    t.name track_name,
    ar.name artist_name,
    mt.name track_type,
    il.unit_price,
    il.quantity
FROM invoice_line il
INNER JOIN track t ON t.track_id = il.track_id
INNER JOIN media_type mt ON mt.media_type_id = t.media_type_id
INNER JOIN album al ON al.album_id = t.album_id
INNER JOIN artist ar ON ar.artist_id = al.album_id
WHERE il.invoice_id = 4;

What I expected to happen:

Output matching records from joined tables with correct number of rows. Checked solution which was identical to my own.

What actually happened:

![Screen Shot 2020-04-11 at 12.20.22 pm|690x166](upload://nA5zmqc9X9mvWFRfq6MlcbBpKSr.png)  

"There are fewer rows than there should be" when submitting answer

hey @mattrosinski

please review your last INNER JOIN. you have two different columns being compared!

1 Like

Thanks @Rucha, looking at it today it’s obvious. Yesterday I was oblivious to my mistake. :slightly_smiling_face:

1 Like