It will return the Cartesian product of the two tables, which means that every combination of emp and department will be included in the result.
I believe the following question: Blockquote
How do you show the right department for each employee?
That is, show only the combination of emp and department , where the employee belongs to the department.
It can be done:
SELECT * FROM emp LEFT JOIN department ON emp.department_id=department.id;
Assuming emp has a field called department_id and department has a corresponding id field (this is pretty standard on these types of questions).
LEFT JOIN means that all elements on the left side ( emp ) will be included, and each employee will be coordinated with the corresponding department. If the corresponding department is not found, the received fields from departments will remain empty. Note that exactly 10 rows will be returned.
To show only employees with valid department IDs, use JOIN instead of LEFT JOIN . This query will return from 0 to 10 rows, depending on the number of identifiers of the compliance department.
source share