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!

1 Answer

Steven Parker
Steven Parker
195,592 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.