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
-- Subquery in WHERE (most common): SELECT name, marks FROM students WHERE marks > (SELECT AVG(marks) FROM students); -- Subquery in FROM (derived table): SELECT * FROM ( SELECT city, AVG(marks) AS avg_marks FROM students GROUP BY city ) AS city_stats WHERE avg_marks > 70;
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 →