Lateral Joins (LATERAL JOIN)
Reference the previous FROM item from inside a subquery with LATERAL — the SQL equivalent of a per-row function call.
What Is LATERAL?
LATERAL lets a sub-select in the FROM clause reference columns from items earlier in the FROM list. Without LATERAL, FROM-items can't see each other.
Mental Model
LATERAL is "for each row of the left side, evaluate this query". It's like a correlated subquery — but in the FROM clause and returning multiple rows/columns.
All lessons in this course
- Cross Joins and Cartesian Products
- Lateral Joins (LATERAL JOIN)
- Anti-Joins and Semi-Joins (NOT EXISTS)
- Multi-Table Join Performance Tuning