---
title: "LATERAL Joins in SQL | Write Smarter SQL Queries"
url: https://daily.dev/posts/lateral-joins-in-sql-write-smarter-sql-queries-nqlqwh79g
source_url: https://www.youtube.com/watch?v=NiiN63lEzvI
type: video:youtube
source: "techTFQ"
published: 2026-05-31T07:43:29.312Z
updated: 2026-05-31T07:55:27.800Z
tags: ["backend", "sql"]
reading_time: 15
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# LATERAL Joins in SQL | Write Smarter SQL Queries

**[techTFQ](https://daily.dev/sources/techtfq)** · 15 min read · 0 upvotes · 0 comments

## Summary

SQL's LATERAL keyword allows subqueries in the FROM clause to reference columns from tables listed earlier in the same query — similar to correlated subqueries but used in the FROM list rather than WHERE. A simple student-courses example demonstrates the error that occurs without LATERAL and how adding the keyword resolves it. A more practical customer-orders example shows how LATERAL can replace a CTE-based approach to find orders exceeding each customer's average spend, resulting in a more compact and readable query. Performance trade-offs are noted: LATERAL executes the subquery per outer row, so it's not always optimal, but it's valuable when passing outer table columns into subqueries is necessary.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=NiiN63lEzvI>

## Similar posts on daily.dev

- [How to Work with Subqueries in SQL](https://daily.dev/posts/how-to-work-with-subqueries-in-sql-jnhjx5ogs) · freeCodeCamp · 14 upvotes · 0 comments

---

Tags: [#backend](https://daily.dev/tags/backend), [#sql](https://daily.dev/tags/sql)

[View this post on daily.dev](https://daily.dev/posts/lateral-joins-in-sql-write-smarter-sql-queries-nqlqwh79g)
