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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Paul Ownby](https://uploads.teamtreehouse.com/production/profile-photos/89946/micro_PaulOwnby2.jpg)
Paul Ownby
23,414 PointsI cannot get a correct answer for Task #4 on the last Challenge for Querying Relational Databases. What's wrong?
On task #4 of the last coding challenge, I am getting an error but I have confirmed by manually looking and comparing both tables that the table returned is correct. What am I missing?
Error: Bummer! The subquery didn't return all CustomerIDs for people who identify as female (F).
Query: SELECT s.SaleID, s.CarID, s.CustomerID, s.LocationID, s.SalesRepID, s.SaleAmount, s.SaleDate FROM Sale AS s INNER JOIN ( select * from Customer c where c.Gender = "F" ) AS cust ON cust.CustomerId = s.CustomerId
URL: https://teamtreehouse.com/library/querying-relational-databases/subqueries/subqueries
2 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsYou might be working too hard.
Try simplifying the query, remove unneeded aliases and select only the field you need in the subquery.. Something like this:
SELECT * FROM Sale AS s
INNER JOIN (SELECT CustomerID FROM Customer where Gender = "F") AS cust
ON cust.CustomerId = s.CustomerId;
![Christian Scherer](https://secure.gravatar.com/avatar/3f460d661013790b063af087eeaa0ffa?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Christian Scherer
2,989 PointsHi Steven,
Thank you for your answer which helped me to complete this task.
Question: I had the exact same code BUT used SELECT s.* FROM Sale AS s... Which did not work.
Any idea why I cant use the Alias "s" at this point?
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsSpecifying "s.*
" instead of "*
" would display only the columns from the Sale table and would omit the joined field.
Paul Ownby
23,414 PointsPaul Ownby
23,414 PointsThanks Steven. Unfortunately, that doesn't work either. I even tried s.* in the select as the requirement is to only return columns from the Sale table and it is still is giving the same error. I think this might be a bug.
I just tried it again and now it works. Weird. Thanks for the help!
Steven Parker
230,688 PointsSteven Parker
230,688 PointsThat's very odd because if I copy that query from the box above and paste it directly into the challenge (for task 4), it passes.
Paul Ownby
23,414 PointsPaul Ownby
23,414 PointsI found the difference. I was using select * in the subquery. I suspect that that was not an acceptable answer because the subquery was returning more rows that it needed to complete the query. Changing * to CustomerId did the trick. Thanks again Steven!