Databases Querying Relational Databases Joining Table Data with SQL JOIN Queries

Chris Gauthier
PRO
Chris Gauthier
Pro Student 6,434 Points

Interesting problem (to me, anyway). Im know I need 3 joins, but im not sure whats wrong with this. Can you help?

Have I made a mistake in the syntax of these queries?

Chris Gauthier
Chris Gauthier
Pro Student 6,434 Points

Woops, i thought I had checked include code. Anyway, here we go:

select Make.MakeName,Model.ModelName,Car.VIN,Car.StickerPrice from Make inner join on Make.MakeId = Model.MakeId inner join Model.modelid = car.modelid

Can you help me fix this and comment as to what happened?

Thanks

2 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,836 Points

This should make it easier to see. Your code is on top. The revised code is on bottom.

select Make.MakeName,Model.ModelName,Car.VIN,Car.StickerPrice
from Make
inner join on Make.MakeId = Model.MakeId
inner join Model.modelid = car.modelid
SELECT Make.MakeName,Model.ModelName,Car.VIN,Car.StickerPrice
FROM Make
INNER JOIN Model ON Make.MakeId = Model.MakeId
INNER JOIN Car ON Model.modelid = car.modelid;

Your inner joins need to include the table name to join and the keyword ON to specify what columns are joining.

Chris Gauthier
PRO
Chris Gauthier
Pro Student 6,434 Points

ah that was a silly mistake lol.

But also, another note to your solution (so that other's don't get confused -- and it was a second mistake i made up above):

Note, Make.MakeName was not asked for in the query, and the query will not pass until it is removed.

Thanks very much for your help Chris

SELECT Model.ModelName,Car.VIN,Car.StickerPrice
FROM Make
INNER JOIN Model ON Make.MakeId = Model.MakeId
INNER JOIN Car ON Model.modelid = car.modelid;