AI engineering glossary · SQL databases

What is correlated subquery?

Correlated subquery: A subquery that refers to columns of the outer query, so it is logically re-evaluated for each outer row. It can be slow if the optimiser cannot rewrite it as a join.

Level: advancedTopic: SQL databases

Correlated subquery: an example

For each employee, (SELECT MAX(salary) FROM employees WHERE dept = e.dept) finds the highest salary in that employee's department.

Related terms

More SQL databases terms

Where you learn it

Correlated subquery is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.