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 Querying Relational Databases Joining Table Data with SQL JOIN Queries

Returning non joined columns with an inner join

I have tried everything to figure this out, even googled to no avail. What am I missing? How do I display columns that are not being joined using inner join? My code keeps saying ModelName, VIN and StickerPrice are not being displayed.

2 Answers

Gergely Bocz
Gergely Bocz
14,244 Points

Hi Aquoinette Blair!

Can you share the some examples that you tried? It would help me greatly in finding the source of the problem.

However, I see some potential misunderstandings in you question that I would like to clarify now.

Joins in SQL don't join columns, they join tables. And tables are joined based ON a shared column! What this means, is that the SELECT command (what you actually display) is separate from the JOIN command!

The way I look at joining different tables of a database looks like this:

  1. Decide what tables I want to join together (based on what data I actually need)
  2. Find the column that they share (Primary key and Foreign key)
  3. Select those column only that hold relevant information to me

This is how I would do the challenge: In the challenge we have the Car and Model tables that we want to JOIN together ON ModelID, since that is their shared columns. Then we want to write our SELECT, so that only Model Name, VIN and Sticker Price are selected.

I hope I could help, if you have any questions please ask!

Good luck, GergΕ‘

Thank you. My terminology was wrong but I do understand that it joins on tables. This is the one I wrote today:

SELECT ModelName, Mod.ModelID, Cars.ModelID, Cars.VIN, Cars.StickerPrice FROM Model as Mod INNER JOIN Car as Cars ON Mod.ModelID = Cars.ModelID;

I don't remember the other ones I wrote but I did several that failed. I can try and recreate the errors if needed. Thanks for your help.

Gergely Bocz
Gergely Bocz
14,244 Points

Your query looks good, but the challenge asked specifically for ModelName, VIN and StickerPrice. Also, if you rename tables, stick to the dot notation when selecting columns for the sake of clarity. I rewrote your query to be acceptable to the challenge like this:

SELECT Mod.ModelName, Cars.VIN, Cars.StickerPrice FROM Model as Mod INNER JOIN Car as Cars ON Mod.ModelID = Cars.ModelID;

In short, you should focus on writing the exact query that the challenge asks for. Any excess or hiatus in the data will fail the challenge. If you want to be more creative or if you need to see more information from the database, I suggest you open the workspace with the relevant tables and play around with those. Write queries first that help you grasp how the database looks like and once you have that, rewrite the query according to the challenge's requirements.

If you have any more questions, feel free to ask! Good luck!