0PricingLogin
SQL Academy · Lesson

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

  1. Cross Joins and Cartesian Products
  2. Lateral Joins (LATERAL JOIN)
  3. Anti-Joins and Semi-Joins (NOT EXISTS)
  4. Multi-Table Join Performance Tuning
← Back to SQL Academy