Databases Querying Relational Databases Joining Table Data with SQL JOIN Queries

Show all SaleDate, SaleAmount, and SalesRep First and Last name from Sale and SalesRep. Make sure that all Sales appear

The full question is: In a car database there is a Sale table with columns, SaleID, CarID, CustomerID, LocationID, SalesRepID, SaleAmount and SaleDate. The database also has a SalesRep table with columns, SalesRepID, FirstName, LastName, SSN, PhoneNumber, StreetAddress, City, State and ZipCode. Show all SaleDate, SaleAmount, and SalesRep First and Last name from Sale and SalesRep. Make sure that all Sales appear in results even if there is no SalesRep associated to the sale.

My code looks like this: SELECT SaleDate, SaleAmount, FirstName, LastName FROM SalesRep LEFT OUTER JOIN Sale ON SalesRep.SalesRepID = Sale.SalesRepID;

But i keep getting this error message: Bummer: Your query didn't select the SaleDate, SaleAmount, FirstName and LastName correctly!

1 Answer

Sarat Chandra
Sarat Chandra
4,898 Points

Hi Sofia, Remember you need to get all Sales even if there is no SalesRep associated to the sale. But your query gets only such sales that have SalesRep associated. Since it is left outer join it matters which table name you put after FROM. Hope this hint helps!