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

Nuno Trindade
seal-mask
.a{fill-rule:evenodd;}techdegree
Nuno Trindade
iOS Development Techdegree Student 4,465 Points

I'm getting "Your query didn't select the `FirstName`, `LastName`, `VIN` and `SaleAmount`!.". Is VIN requested?

What am I doing wrong in task 3 of code challenge?

Challenge "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."

Code

select FirstName, LastName, sum(SaleAmount) SaleAmount from Sale inner join SalesRep on Sale.SalesRepId = SalesRep.SalesRepId group by FirstName, LastName

Edited by Dane E. Parchment Jr. for readability and clarification of problems

Can you link to the challenge as well as the query you're trying?

Andrew Chalkley ,

Task 3 of the following challenge seems to have an incorrect error message.

https://teamtreehouse.com/library/querying-relational-databases/joining-table-data-with-sql/join-queries

The error message is in the title of this question. It requests a vin column even though the instructions don't ask for it.

4 Answers

Hi Nuno,

It does seem like there's an incorrect error message here. The instructions don't request it.

I think the problem is that you're trying to do more than is requested. It's not asking for a total sales amount so you probably shouldn't be aggregating the results. I think the goal here is to list out every sale made. If a sales rep made 10 sales then they would have 10 entries in the results showing each of their 10 sales.

By taking out the group by clause and the sum() aggregate function I came up with this which passed:

select FirstName, LastName, SaleAmount from Sale inner join SalesRep on Sale.SalesRepId = SalesRep.SalesRepId
Andrew Chalkley
Andrew Chalkley
Treehouse Guest Teacher

I've fixed the VIN error it shouldn't show any more. You're right Jason, no aggregate needed in this Code Challenge.

Thanks Andrew.

Nuno Trindade
seal-mask
.a{fill-rule:evenodd;}techdegree
Nuno Trindade
iOS Development Techdegree Student 4,465 Points

Apparently the Attach my code to this post option does not seem to work!? The code I've used is the following:

select FirstName, LastName, sum(SaleAmount) SaleAmount from Sale inner join SalesRep on Sale.SalesRepId = SalesRep.SalesRepId group by FirstName, LastName

The challenge below does not request the VIN column as the error states:

"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."

I've tried with and without column and table aliases and the result is the same. Maybe I didn't got the challenge correctly. Could you please help? Thanks a lot

Alain De La Cuadra
Alain De La Cuadra
21,890 Points

Can you please help me with this thanx

In a car database there is a Model table with columns, ModelID, MakeID and ModelName and a Car table with columns, CarID, ModelID, VIN, ModelYear and StickerPrice. Show all Model names from the Model table along with VIN from the Car table. Make sure models that aren’t in the Car table still show in the results!

Kevin Gates
Kevin Gates
15,053 Points

A correct answer is:

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

Since they want to have sales even if there is no sales rep, that means that there are sales occurring without a sales rep.

If we're implementing a LEFT OUTER JOIN, that means the table on the left needs to always have a value returned. This means we list Sale first after the FROM keyword.