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

Patrik Horváth
Patrik Horváth
11,110 Points

SQL Select SUBQUERIES

https://teamtreehouse.com/library/querying-relational-databases/subqueries/subqueries

Tank 4 Of 4 : 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.

My QUERY with Error : Bummer! The subquery didn't return all CustomerIDs for people who identify as female (F).

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

but i think i have selected them ALL :/

1 Answer

Steven Parker
Steven Parker
231,269 Points

You have indeed created a solution that would return the correct rows. :+1: But the challenge is looking for your sub-query to return only the CustomerID so that final result will *"Select all columns from the Sale table only."

You might also try prefixing that first asterisk with "Sale.". But if that doesn't work, you might want to report it as a bug to Support.

Patrik Horváth
Patrik Horváth
11,110 Points

but if i change * to Sale.CustomerID it is not let me pass this chalange =\

Steven Parker
Steven Parker
231,269 Points

But the table in the sub-query is "Customer", not "Sale". Plus you don't need to prefix the field at all inside the sub-query, since there is only one source.

And to facilitate the most accurate answers, always provide a link to the course page you are working with.

Patrik Horváth
Patrik Horváth
11,110 Points

after getting : fd7e0c01-7ddb-460c-81c2-c11f3d124e64.rb:35:in eval': undefined methodshift' for "SQL Error: no such column: Customer":String (NoMethodError) from fd7e0c01-7ddb-460c-81c2-c11f3d124e64.rb:35:in `eval' from fd7e0c01-7ddb-460c-81c2-c11f3d124e64.rb:35:in

it worked :D, Thanks :)