Databases Querying Relational Databases Subqueries Subqueries

Skylar Gordon
Skylar Gordon
7,234 Points

What does this return, if it doesn't return all sales to female customers?

So, I am being told by the computer that this is not correct, as it does not return all columns of the rows in the Sale table that have Customer IDs that belong to female customers. If it doesn't return that, what does it return? Since the challenges won't show you what you queried unless you got it right, I can't actually problem solve this until I have that information. (I did a very similar query in the SQL playground for the last task, and got what I thought I'd get, so not being able to see what this queries is the only reason I can't figure this out.)

ETA code:

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

2 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,852 Points

Although your query may return the same results the task specifically asks Use a subquery along with IN to list all sales to female customers . It is similar to the previous two tasks.

Skylar Gordon
Skylar Gordon
7,234 Points

The one after it asks we do it as a subquery of a derived table - I managed to do the one with IN.

Josh Gabel
Josh Gabel
8,261 Points

Not sure if you found a solution or not but the challenge appears to be worded incorrectly. It specifically says:

Select all columns from the Sale table only.

However the accepted result is all columns of the Sale table and the result of the derived table. This query will work:

SELECT s.*, c.CustomerID
FROM Sale AS s INNER JOIN (SELECT CustomerID FROM Customer WHERE Gender = 'F') AS c ON c.CustomerID = s.CustomerID;