Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
208,472 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.

Ariadna Rodriguez
Ariadna Rodriguez
6,274 Points

Here is my solution that passed;

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