Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases

DERIVED Subquery to find all Female customer sales data (under Challenge Task)

This is Challenge Task #4 for SQL Querying Relational Databases

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

What am I doing wrong?

Do you have a link to the task?

4 Answers

SELECT * FROM sale AS s
           INNER JOIN (SELECT customerid FROM customer WHERE gender = 'F') AS c
           ON s.customerid = c.customerid;

On the inner join, I am selecting customerid and you are selecting all.

Steven Parker
Steven Parker
220,378 Points

This gets the right rows, but with much more data than expected.

The challenge is expecting your subquery to select only the customer ID's from the Customers table, not all the columns.

Changing that worked, thanks!

Can you clarify why having all the columns wouldn't work considering all the Males were filtered out?

Steven Parker
Steven Parker
220,378 Points

That "Select all columns from the Sale table only." is your clue. Your current subquery would also give you every column from the Customers table, which is not what the challenge expected to see.

nolan emirot
nolan emirot
2,826 Points

If we specify all the columns instead of "*" it won't work but it's correct...