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

Gurdeep singh
Gurdeep singh
1,522 Points

NEED HELP SQL SUBQUERY IT'S difficult

Generate a report that lists the book titles from both locations and count the total number of books with the same title?

I'm doing a task but I really Can find the solution https://teamtreehouse.com/sql_playgrounds/522#/queries/670ffc6e-68f8-4117-aeda-a3bd5d37d4b3

Steven Parker
Steven Parker
231,269 Points

Please show your query and we can give you some hints on it.

Gurdeep singh
Gurdeep singh
1,522 Points

Steven Parker , I'm confused with GROUP BY it is used to group common attributes right?

Example: Column with multiple values like State Salary Cali 2000 Cali 12000 Texas 5000 NY 6000 Texas 7000 NY 1000

To get the sum of the salaries we can group it by the common attribute or I should say repeating values that is state like

SELECT STATE, SUM(Salary) FROM ABC GROUP BY STATE;

Now there is one more examples that really confuse me SEE THIS VIDEO https://teamtreehouse.com/library/outer-joins

Andrew Chalkley Used mk.makename to group by. Where if you look at the make table you have.

MakeID (PK) MakeName

1 Ford 2 Chevy 3 Jeep 4 Dodge 5 Honda 6 Kia 7 Toyota 8 BMW

NO repeating values this is really confusing me cause I know I'm missing on something.

1 Answer

Steven Parker
Steven Parker
231,269 Points

The GROUP BY combines the rows that have the same value in the grouping field, that's why you only get one of each make in the output. But you'll notice the count of items will tell you how many there actually were in the table.

Similarly, your query with states and salaries would show only one row for each state, but the total of all salaries for that state.

Did you still need any help with the books query? Please show that one if so.