It would return the Cartesian Product of the two tables, meaning that every combination of emp
and department
would be included in the result.
I believe that the next question would be:
Blockquote
How do you show the correct department for each employee?
That is, show only the combination of emp
and department
where the employee belongs to the department.
This can be done by:
SELECT * FROM emp LEFT JOIN department ON emp.department_id=department.id;
Assuming that emp
has a field called department_id
, and department
has a matching id
field (This is quite standard in these type of questions).
The LEFT JOIN
means that all items from the left side (emp
) will be included, and each employee will be matched with the corresponding department. If no matching department is found, the resulting fields from departments
will remain empty. Note that exactly 10 rows will be returned.
To show only the employees with valid department IDs, use JOIN
instead of LEFT JOIN
. This query will return 0 to 10 rows, depending on the number of matching department ids.