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

Shawn Jass
Shawn Jass
7,151 Points

Trying to get the code corrected

Select name.FirstName, name.LastName, Sale.SaleID, Sale.SalesRepID, Sale.SaleAmount from Sale inner join Model on Sale.SaleAmount

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Hey Shawn,

You will need to provide a direct link to the challenge you are referring to, in order for us to be able to accurately help you troubleshoot what is wrong.

:dizzy:

1 Answer

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

That is task 2 of challenge https://teamtreehouse.com/library/querying-relational-databases/subqueries/subqueries

First we cannot use the JOIN in this challenge.

We need to used IN only.

How did you solve first task? Take a look at this guy solution, he also explains logic:

https://teamtreehouse.com/community/help-with-challenege-1-of-4

So the constraint of the Task 2 is exactly like in Task 1:

  • use only one subquery with IN keyword where you select foreign_key

So the solution will look like this

  1. select everything from sale

  2. in where condition we write IN and subquery that selects CarId from Car with price > 30000.

SELECT * FROM Sale 
WHERE CarId IN ( 
  SELECT CarId 
  FROM Car 
  WHERE StickerPrice > 30000 
);