MySQL: Which join is better between left outer join and inner join
There is not a "better" or a "worse" join type. They have different meaning and they must be used depending on it.
In your case, you probably do not have employees with no work_log
(no rows in that table), so LEFT JOIN
and JOIN
will be equivalent in results. However, if you had such a thing (a new employee with no registered work_log
), a JOIN
wold omit that employee, while a left join (whose first table is employees) would show all of them, and nulls on the fields from work_log
if there are not matches.
Image by C.L. Moffatt on Code Project
Again, performance is a secondary thing to query correctness. Some people say that you shouldn't use LEFT JOIN
s. It is true that a LEFT JOIN
forces the optimizer to execute the query in one particular order, preventing some optimizations (table reordering) in some cases. Here is one example. But you should not choose one over the other if correctness/meaning is sacrificed, as an INNER JOIN
is not inherently worse. The rest of the usual optimizations apply as usual.
In summary, do not use LEFT JOIN
if you really mean INNER JOIN
.
In MySQL CROSS JOIN
, INNER JOIN
and JOIN
are the same. In the standard, and semantically, a CROSS JOIN
is an INNER JOIN
without an ON
clause, so you get every combination of rows between tables.
You have examples of all semantic types of join on Wikipedia. In practice, in MySQL, we tend to only write JOIN
and LEFT JOIN
.