Databases Querying Relational Databases Subqueries Subqueries

Jason Finley
Jason Finley
13,168 Points

I have no idea why this isn't returning the right amount of rows. Please tell me what I've got wrong here.

I don't know what I'm missing since I cannot see the results.

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,289 Points

Can you show your SQL and/or identify the task?

Jason Finley
Jason Finley
13,168 Points

I'm sorry. I thought it was supposed to include my code with this question. It's for the final code challenge for the Querying Relational Databases course. My code is as follows: select s.* from sale s inner join (select customerid from customer where gender = 'F') c on s.customerid = c.customerid

The question is: "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."

And my query returns: "Your query didn't return all columns from the Sale table for who's CustomerIDs belong to people who identify as female!"

Gabriel Pierce-Lackey
Gabriel Pierce-Lackey
11,005 Points

Your subquery is only selecting customerID from Customer, which is then also a column in Sales. Then joining on the CustoemrID which is then the only column in Customer. So user SELECT * will automatically only select everrything from Sales since that's all there is left to select anyways.

1 Answer

Gabriel Pierce-Lackey
Gabriel Pierce-Lackey
11,005 Points

You just need to removed the s.

SELECT * FROM sale s INNER JOIN (select customerid FROM customer WHERE gender = 'F') c on s.customerid = c.customerid
Jason Finley
Jason Finley
13,168 Points

That worked, but I'm curious. The question specifically says, "Select all columns from the Sale table only." Doesn't your solution select all columns from both the Sale table and the Customer table?