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 trialJan Lundeen
5,886 PointsSubqueries - Challenge 4 of 4 - still getting error
Hi,
I was working the questions for subqueries, Challenge 4 of 4. Here's the question:
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 as a derived table to show all sales to female ('F') customers. Select all columns from the Sale table only
Here's my query: SELECT * FROM Sale AS s INNER JOIN(SELECT CustomerID FROM Customer WHERE Gender = âFâ) AS c ON s.CustomerID = c.CustomerID;
I keep on getting an error (Bummer! There's something wrong with your SQL statement. Please review your code and try again). It wasn't very specific.
I looked at the other questions posted on this question in the community. It looks like my query should be correct. However, I'm probably overlooking something. Can you help me out with this?
Thanks,
Jan
Jan Lundeen
5,886 PointsThanks! I tried LEFT JOIN and LEFT OUTER JOIN, but it didn't work. I got the following error message:
You're missing the INNER JOIN keywords.
Any other ideas?
Jan
5 Answers
jahid ali
2,311 PointsHello Jan Lundeen,
Give this a go:
SELECT * FROM sale AS s
INNER JOIN (SELECT customerid FROM customer WHERE gender = 'F') AS c
ON s.customerid = c.customerid;
Jan Lundeen
5,886 PointsThanks Jahid! That worked. The only difference between your query and mine was that customerid is lowercase. Weird stuff, but it worked.
Jan
Farai Tanekha
10,669 PointsMerci mille fois :)
ds1
7,627 PointsShouldnt there be a space between join & (select, below: "INNER JOIN(SELECT CustomerID
Other than that, I dunno and will have to leave it to the experts as I'm still a sql beginner : )
Jan Lundeen
5,886 PointsThanks for trying, but I'm not sure that's what's causing it.
Giovanni Esposito
7,830 PointsHello Jan Lundeen,
Try using the aliase on SELECT * to indicate from wich table you require the columns, for example: SELECT s.* FROM Sale AS s INNER JOIN(SELECT CustomerID FROM Customer WHERE Gender = âFâ) AS c ON s.CustomerID = c.CustomerID;
Jan Lundeen
5,886 PointsHi Giovanni,
Thanks for trying, but that doesn't work either.
Jan
Tapiwanashe Taurayi
15,889 PointsSELECT * FROM sale AS s INNER JOIN (SELECT customerid FROM customer WHERE gender = 'F') AS c ON s.customerid = c.customerid;
Ka'ohu Ah Yo
Front End Web Development Techdegree Student 8,520 PointsMy exercise required the IN...
SELECT * FROM Sale WHERE CustomerID IN (SELECT CustomerID FROM Customer WHERE Gender = "F");
ds1
7,627 Pointsds1
7,627 PointsHi, Jan maybe try a left join instead of and inner join, as the instructions mention "... Sale table only". Hope this helps, D.