SQL Practice Logo

SQLPractice Online

Correlated Subqueries: Performance

Module: Subqueries & CTEs

Correlated subqueries execute once per outer row. For 10,000 rows, that's 10,000 executions. Without indexes, this means 10,000 full table scans. With proper indexes on correlated columns, performance improves dramatically. Consider window functions or JOINs as faster alternatives for aggregations.

Very expensive

Index all columns

Consider alternatives

Performance issues

Not considering alternatives

Missing indexes