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

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

You 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;

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

That'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.

I 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!

Christian Scherer
Christian Scherer
2,989 Points

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

Specifying "s.*" instead of "*" would display only the columns from the Sale table and would omit the joined field.