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 trialJames Head
18,872 PointsQuerying Relational Databases SubQueries Question Help
Im stuck on question 3/4 in the Querying Relational Databases SubQueries course.
The question is:
"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 answer is:
"SELECT * FROM Sale WHERE SaleID IN (SELECT CustomerID FROM Customer WHERE Gender = 'F');"
However I'm getting the following error:
"Your query didn't return all columns from the Sale table for who's CustomerIDs belong to people who identify as female!"
Please could someone help!
Thank you
2 Answers
Umesh Ravji
42,386 PointsSELECT * FROM Sale WHERE **SaleID** IN (SELECT CustomerID FROM Customer WHERE Gender = 'F');
You are obtaining a collection of CustomerID's from the subquery, but then you are selecting customers from the Sale table based on SaleID when you should be selecting them based on CustomerID
Sean M
7,344 PointsSELECT * FROM Sale WHERE CustomerID IN (SELECT CustomerID FROM Customer WHERE Gender = 'F');
- Select all from sale table
- Specifying customer id from the customer table
- specifying the gender be female.
note: a single letter/char is represented in single quotation: 'F'
Kevin Gates
15,053 PointsThis, but with Markdown
SELECT * FROM Sale WHERE CustomerID IN
(SELECT CustomerID FROM Customer WHERE Gender = 'F');
James Head
18,872 PointsJames Head
18,872 PointsGreat, thank you Umesh.