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 trialFairooz Adams
2,704 PointsKeep getting an error.
Hi all again, what would be the correct answer for this one?
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.
Fairooz Adams
2,704 PointsBrendan Whiting SELECT * FROM Sale WHERE "SaleID" IN (SELECT CustomerID FROM Customer WHERE Gender = 'F');
And the error I keep getting: Bummer: Your query didn't return all columns from the Sale table for who's CustomerIDs belong to people who identify as female!
2 Answers
Steven Parker
231,236 PointsWhen you use "IN" with a subquery to match items, it's important to be sure the subquery is selecting the same kind of item as the one you want to match with. In your example, your subquery is selecting "CustomerID", but the WHERE clause is trying to match it with "SaleID".
Try changing your WHERE clause to match on "CustomerID" to go with what the subquery is selecting.
Fairooz Adams
2,704 PointsThank you! It works.
Ariadna Rodriguez
6,281 PointsHere is my solution that passed;
SELECT * FROM Sale WHERE CustomerID IN ( SELECT CustomerID FROM Customer WHERE Gender = "F" );
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsWhat's the SQL query that you're attempting that's giving you an error?