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

Issues with subquery challenge task.

I am trying to complete one of the subquery challenge tasks and keep getting it wrong despite my best efforts. The case is as follows: In a car database there is a Sale table with columns, SaleID, CarID, CustomerID, LocationID, SalesRepID, SaleAmount and SaleDate and a Customer table with columns, CustomerID, FirstName, LastName, Gender and SSN. Use a subquery along with IN to list all sales to female customers. (Gender = 'F') Select all columns. My query is: SELECT * FROM Sale WHERE CustomerID IN (SELECT CustomerID FROM Customer WHERE Gender = 'F') AS c ON Sale.CustomerID = c.CustomerID;

Umesh Ravji
Umesh Ravji
42,386 Points

Could you please clarify, is it task 3 or 4 you are having this issue with?

Hi, Umesh. It's for challenge task 3.

1 Answer

Steven Parker
Steven Parker
231,271 Points

You seem to have mixed two different queries together.

Your query makes sense up through the sub-query, but starting with "AS ..." the rest does not appear to belong there. Did you originally write this using a JOIN and then convert it to a subquery?

Try removing everything after and including AS.

Ahhh. Thank you Steven. You were correct. The first time I tried submitting my answer I was using an inner join before realizing I didn't IN in my WHERE statement. Thank you so much!

Thank you soooo much :)