Home › coding › sql › sql subqueries

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.

✓ 100% Free ✓ No Login Needed ✓ NCERT / CBSE Aligned ✓ Download as PDF

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 Jul 14, 2026

🤖 Stuck on any question? Ask Syllab's free AI Tutor for a step-by-step explanation — instant, unlimited, no login.

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 →

Explore:

  • Syllabus
  • Practice
  • Mock Tests
  • NCERT Solutions
  • Coding
  • GK Quiz
  • Career Predictor
  • AI Tutor
  • Live Quiz
  • Doubt Solver
  • Microlearning
  • Free Alternatives
  • Kids Zone
  • Study Room
  • Calculators
  • Worksheets

Syllab.in — Free learning for Indian students, Class 1–12