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 trial

Databases Querying Relational Databases Joining Table Data with SQL JOIN Queries

Tadjiev Codes
Tadjiev Codes
9,626 Points

In a car database there is a Sale table with columns, SaleID, CarID, CustomerID, LocationID, SalesRepID, SaleAmount and

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 the First and Last Name of each sales rep along with SaleAmount from both the SalesRep and Sale tables in one result set.

SELECT firstname, lastname, salesrepid, saleamount
FROM sale sa
INNER JOIN salesRep AS sr 
ON saleid = SalesRepID;

It returns ambiguous salesrepid name? What's the problem here?

Tadjiev Codes
Tadjiev Codes
9,626 Points

Actually It shsould be with sa. and sr. But doesn't seem to be correct yet.

SELECT firstname, lastname, salesrepid, saleamount
FROM sale sa
INNER JOIN salesRep AS sr 
ON sa.saleid = sr.SalesRepID;

I takes too long time to load these challenges exactly in this part sometimes gives correct and sometimes wrong. Mailed to Treehouse help to fix it

3 Answers

Steven Parker
Steven Parker
231,236 Points

You're getting close, but the challenge asks for "the First and Last Name of each sales rep along with SaleAmount", it does not ask for the salesrepid.

Also, when you join tables, the ON terms should be something both tables have in common. So here, you'd want to use the SalesRepID in both tables instead of sa.saleid in one of them.

Tadjiev Codes
Tadjiev Codes
9,626 Points

Alright Thanks a lot)

SELECT firstname, lastname, saleamount
FROM sale sa
INNER JOIN salesRep AS sr 
ON sa.SalesRepID = sr.SalesRepID;

This is okay now

Julian Jaramillo
Julian Jaramillo
7,265 Points

Hey there, I'm using this query, but it tells me I'm missing the IN keyword. Could you please tell me what am I missing? Thanks

Steven Parker
Steven Parker
231,236 Points

Start a fresh question and show your exact code in it. You may want to take a look at this video about Posting a Question.

SELECT sa.SaleDate, sa.SaleAmount, sr.FirstName, sr.LastName FROM Sale sa LEFT OUTER JOIN SalesRep sr ON sa.SalesRepID = sr.SalesRepID;

Steven Parker
Steven Parker
231,236 Points

:warning: FYI: According to a moderator, explicit answers without any explanation are strongly discouraged by Treehouse and may be subject to redaction.