Sql Correlated Subquery — Free Sql Tutorial
Learn Sql Correlated Subquery in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Sql Correlated Subquery in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Sql Correlated Subquery in Sql
A correlated subquery references outer query columns — it runs once per outer row, making it slower than JOINs but more readable for some problems.
Use case: "find students scoring above their class average", "find orders with above-average amount", "find employees with more-than-average salary for their department".
Prefer JOINs for performance. Use correlated subqueries when readability is more important or the logic is complex.
Sql Correlated Subquery — Syntax
SELECT name, marks FROM students s
WHERE marks > (
SELECT AVG(marks) FROM students WHERE class_id = s.class_id
);
SELECT customer, amount FROM orders o
WHERE amount > (
SELECT AVG(amount) FROM orders WHERE customer_id = o.customer_id
);
Learn Sql Correlated Subquery step by step with Syllab's free interactive Sql tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full Sql course →