Subqueries & CTEs

Scalar Subqueries: Overview

Master scalar subqueries that return exactly one value (1 row, 1 column) Use scalar subqueries in SELECT, WHERE, and HAVING clauses effectively Compare individu

Master scalar subqueries that return exactly one value (1 row, 1 column)

Use scalar subqueries in SELECT, WHERE, and HAVING clauses effectively

Compare individual values to aggregates (average, max, min, median)

Calculate dynamic thresholds and percentage differences on the fly

Understand when scalar subqueries execute once vs per row (correlated)

Avoid the "subquery returns more than one row" error with proper techniques

Optimize scalar subquery performance with indexes and caching strategies

Choose between scalar subqueries, JOINs, and variables for best performance

Master scalar subqueries that return exactly one value (1 row, 1 column)

Use scalar subqueries in SELECT, WHERE, and HAVING clauses effectively

Compare individual values to aggregates (average, max, min, median)

Calculate dynamic thresholds and percentage differences on the fly

Understand when scalar subqueries execute once vs per row (correlated)

Avoid the "subquery returns more than one row" error with proper techniques

Optimize scalar subquery performance with indexes and caching strategies

Choose between scalar subqueries, JOINs, and variables for best performance