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 Subqueries Subqueries

Keep 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.

Brendan 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
Steven Parker
231,271 Points

When 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.

Thank you! It works.

Here is my solution that passed;

SELECT * FROM Sale WHERE CustomerID IN ( SELECT CustomerID FROM Customer WHERE Gender = "F" );