Correlated Subqueries — Advanced Filtering — Free SQL Tutorial
Learn Correlated Subqueries — Advanced Filtering in SQL with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Correlated Subqueries — Advanced Filtering in SQL with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.i…
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Correlated Subqueries — Advanced Filtering 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.
Correlated Subqueries — Advanced Filtering — 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 Correlated Subqueries — Advanced Filtering 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 →