Going fast! #DataquestChallenge Premium Annual Offer:
500 get 50% & the next 1000 get 40% off.
GET OFFER CODE

Not sure how my answer differs from the correct answer

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,
    artist.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 ON album.album_id = track.album_id
INNER JOIN artist ON artist.artist_id = album.artist_id
WHERE il.invoice_id = 4;

What I expected to happen:
I feel like this matches the correct answer less the aliases?

What actually happened:

(sqlite3.OperationalError) near "mt": syntax error
[SQL: SELECT     il.track_id,     t.name track_name,     artist.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 ON album.album_id = track.album_id INNER JOIN artist ON artist.artist_id = album.artist_id WHERE il.invoice_id = 4;]
(Background on this error at: http://sqlalche.me/e/13/e3q8)

As you can see, I’m getting an error but I don’t know why. Thanks!

The error, while not always clear enough, does point you in the direction of the source of the problem -

So, it’s a syntax error near mt in your code. So, looking at your code near mt and you can see -

You are missing a comma , after artist_name and hence the syntax error.

1 Like