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 SQL Reporting by Example Day 2: Advanced Selecting Day 2: Review

trouble

The EMPLOYEES table has 267 rows and the JOBS table has 28 rows. How many ROWS does the following query return?

SELECT * FROM EMPLOYEES JOIN JOBS ON EMPLOYEES.JOB_ID = JOBS.ID;

Why does this not return 267 rows? I'm selecting everything from Employees. I'm joining the Jobs table, but I still have 267 rows in the Employees table.

1 Answer

Steven Parker
Steven Parker
231,248 Points

The word "JOIN" by itself is short for "INNER JOIN". So it will return rows where both tables have a JOB_ID (or ID) in common.

Since we don't have any idea what the table contents are, the output could have no rows at all (if there are no ID's in common) or any number up to the total number of employees (if they all have a JOB_ID found in the JOBS table).

Wow, ok, that makes perfect sense. I had not seen enough examples yet to realize that that is the case. And if it was explained in a module I forgot it :/

Thank you!