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 trialR.P. Arts
22,284 PointsQuerying Relational Databases. Challenge Task 5 of 5 JOIN QUERIES
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.
What is the answer ?
3 Answers
Steven Parker
231,248 PointsI'm resistant to explicit answers, but how about some hints?
The list of things to "Show" will become the terms in your SELECT
clause.
It says, "Make sure that all Sales appear in results even if there is no SalesRep..." That's a hint in itself that you'll be joining the Sales table to the SalesRep table using a LEFT OUTER JOIN
.
What column do the tables share? That will be the term you join ON
.
After considering these hints, can you solve it now?
Dustin Beaulieu
1,279 PointsThis was my answer and I get the results except for the sales without the reps. I thought the left outer table would be the table that would return results even is they didnt match. Any help would be appreciated on this!
SELECT Sale.SaleDate, Sale.SaleAmount, FirstName || " " || LastName FROM SalesRep LEFT OUTER JOIN Sale ON SalesRep.SalesRepID = SalesRep.SalesRepID;
Steven Parker
231,248 PointsThe instructions quoted in the original question don't sound like concatenation is needed (or desired) here. For a more accurate analysis, can you provide a link to the challenge page?
Steven Parker
231,248 PointsThat challenge doesn't seem to use the same table as what Dustin Beaulieu was asking about. Dustin, can you post a link to the challenge you're working on?
Mathias Flaaten
19,253 PointsBummer! Your query didn't select the SaleDate
, SaleAmount
, FirstName
and LastName
!! I Have selected all of them :
SELECT s.SaleDate, s.SaleAmount, sr.FirstName||" "||sr.LastName FROM SalesRep AS sr LEFT OUTER JOIN Sale AS s ON sr.SalesRepID = s.SalesRepID
What Am I missing here?
Steven Parker
231,248 PointsThe challenge is probably not expecting you to concatenate two of the columns instead of selecting them individually.