Sql - LEFT JOIN
Code Life
By Pierre Marsaa
The rows INNER JOIN forgot
In the last lesson, Jordan (no Codémon) and Plantachu (no trainer) silently vanished from every INNER JOIN. Sometimes that is exactly what you want. Sometimes you need every trainer, even the ones with nothing to show.
Loading data...
Loading data...
LEFT JOIN keeps every row of the left table (the one after FROM), matched or not:
LEFT JOIN: all of table 1, plus the matching rows of table 2 - source
↗️
Loading editor...
↶
↷
Jordan is back, with NULL in the codemon column: there was nothing to attach, so the columns coming from codemon are empty. Plantachu is still missing — it is on the right side, and only the left side is protected.
Same syntax, one word changes
LEFT JOIN is written exactly like INNER JOIN, with the same ON condition. You may also see LEFT OUTER JOIN: it is the very same thing, OUTER is optional.
Verify