Sql Subqueries — Free Sql Tutorial
Learn Sql Subqueries in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Sql Subqueries 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 Subqueries in Sql
A subquery (also called a nested query or inner query) is a SQL query written inside another query. The inner query runs first, and its result is used by the outer query.
Subqueries can appear in: WHERE (most common — "find students who scored above the class average"), FROM (treat a query result as a table), SELECT (calculate a value for each row).
Correlated subquery: The inner query references a column from the outer query — it runs once for each row of the outer query. These can be slow but are very powerful.
Sql Subqueries — Syntax
-- Scalar (one value): SELECT name FROM students WHERE marks > (SELECT AVG(marks) FROM students); -- Multi-row (IN): WHERE class_id IN (SELECT class_id FROM classes WHERE section='A'); -- Exists: WHERE EXISTS (SELECT 1 FROM awards WHERE student_id = s.student_id); -- Derived table (subquery in FR
Learn Sql Subqueries 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 →