Databases SQL Reporting by Example Day 2: Advanced Selecting Day 2: Review

Steve Rogers
Steve Rogers
2,343 Points

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
177,671 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).

Steve Rogers
Steve Rogers
2,343 Points

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!