Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,361 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,361 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,258 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.