Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

I Need help trying to solve this:

In a car database there is a Model table with columns, ModelID, MakeID and ModelName and a Car table with columns, CarID, ModelID, VIN, ModelYear and StickerPrice. Show all Model names from the Model table along with VIN from the Car table. Make sure models that aren’t in the Car table still show in the results!

Umesh Ravji
Umesh Ravji
42,386 Points

What have you written so far? Share it with us :)

SELECT ModelName, VIN FROM Model LEFT OUTER JOIN Car ON Model.ModelName = Car.CarID INNER JOIN Car ON Car.ModelID = Model.ModelID;

2 Answers

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Tyler, you're almost there.

FROM Model
    LEFT OUTER JOIN Car ON Model.ModelName = Car.CarID

The two columns ModelName and CarID are not related, so it doesn't make much sense to perform a join using the two.

INNER JOIN Car ON Car.ModelID = Model.ModelID;

This is exactly the part you need for your LEFT OUTER JOIN, so once you replace the first unnecessary join with this one (and make sure it is an LEFT OUTER JOIN , you have your answer :)

SELECT ModelName, VIN
FROM Model
    LEFT OUTER JOIN Car ON Car.ModelID = Model.ModelID;

WOW!! I See where I messed up. Thanks Alot!

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

it's asking you to use a type of join that includes records even if they don't have a match, so focus on that. the two tables have a common column that is used to join them.