AceReady
SQL
Question 1 of 13
Easy

What is the difference between an INNER JOIN and a LEFT JOIN ?

Answer

An INNER JOIN only returns rows that have a match in both joined tables: if a row in the left table has no match in the right table, it's excluded from the result. A LEFT JOIN keeps every row from the left table, even without a match in the right table, filling the right-side columns with NULL in that case. LEFT JOIN is therefore useful when you want, for example, to list every customer, including those who have never placed an order yet.

Common trap

The classic trap is adding a condition on a right-table column in the WHERE clause instead of the ON clause of a LEFT JOIN: that filters rows after the join and silently turns the LEFT JOIN into behavior equivalent to an INNER JOIN.