Databases Querying Relational Databases Subqueries Subqueries

Tommy Gebru
Tommy Gebru
29,403 Points

Challenge Task 4 of 4 Bummer: SQL Error: near "SELECT": syntax error

This is the last challenge task 4 of 4, I couldnt get to an answer or even get a different error message for a while, so I thought to share it here with the community

SELECT *
FROM Sale
INNER JOIN Customer
(SELECT CustomerID
FROM Customer
WHERE Gender = 'F'
) AS "isFemale"
ON Sale.CustomerID = isFemale.CustomerID;

2 Answers

Gabriel Pierce-Lackey
MOD
Gabriel Pierce-Lackey
Treehouse Moderator 10,998 Points

Okay, making progress. With your inner join, you don’t need the table name “customer”. You’re joining a sub query, not a table. So it would be inner join (subquery) as alias on whatever. I think that should do it. But let me know.

Tommy Gebru
Tommy Gebru
29,403 Points

Oh wow that did it - i removed the table name

SELECT *
FROM Sale
INNER JOIN
(SELECT CustomerID
FROM Customer
WHERE Gender = 'F'
) AS "isFemale"
ON Sale.CustomerID = isFemale.CustomerID;
Gabriel Pierce-Lackey
MOD
Gabriel Pierce-Lackey
Treehouse Moderator 10,998 Points

What is you current answer to the challenge? Going blindly on this but based on your error and what I believe the correct answer is, you may need to alias your query join, as something like 'c' then do c.customerID

Tommy Gebru
Tommy Gebru
29,403 Points

I went ahead and shared my code above in the description. I created an ALIAS and provided it as the JOIN criteria at the end of the code

BTW: I got a new error message so treat this as a new question too :eyes: