In ECET 2026 DBMS, SQL Subqueries and Nested Queries are one of the most asked topics. These are easy to learn but scoring if you understand how queries work inside other queries.
📘 Concept Notes – SQL Subqueries & Nested Queries
🔹 What is a Subquery?
- A subquery is a query inside another query.
- The inner query provides data to the outer query.
- Written inside parentheses
( ).
Syntax Example:
SELECT column_name
FROM table_name
WHERE column_name operator (SELECT column_name FROM another_table WHERE condition);🔹 Types of Subqueries
- Single-row Subquery:
- Returns only one value.
Example:
- Returns only one value.
SELECT name
FROM students
WHERE marks = (SELECT MAX(marks) FROM students);- Multiple-row Subquery:
- Returns multiple rows.
Example:
- Returns multiple rows.
SELECT name
FROM students
WHERE marks IN (SELECT marks FROM students WHERE grade = 'A');- Multiple-column Subquery:
- Returns multiple columns.
Example:
- Returns multiple columns.
SELECT name
FROM students
WHERE (marks, grade) IN (SELECT marks, grade FROM toppers);- Correlated Subquery:
- Inner query depends on outer query for its values.
Example:
- Inner query depends on outer query for its values.
SELECT name
FROM students s1
WHERE marks > (SELECT AVG(marks) FROM students s2 WHERE s2.branch = s1.branch);🔹 Nested Queries
- A nested query is another name for subquery.
- Queries can be nested inside SELECT, FROM, or WHERE clauses.
Example (Nested inside FROM):
SELECT AVG(total)
FROM (SELECT SUM(marks) AS total FROM students GROUP BY branch) AS temp;🔹 Important SQL Operators used with Subqueries
| Operator | Description | Used in |
|---|---|---|
| = | Equal to | Single-row subquery |
| IN | Match any value from subquery | Multiple-row subquery |
| ANY | Compare to each value from subquery | Multiple-row subquery |
| ALL | Compare to all values from subquery | Multiple-row subquery |
| EXISTS | Check if subquery returns any rows | Correlated subquery |
🔹 Formula – General Representation of a Subquery
A subquery can be represented as:
![]()
Where:
= Subquery providing intermediate results.
= Main query that uses those results.
💡 Example – Find Students with Marks Greater than Average Marks
SELECT name, marks
FROM students
WHERE marks > (SELECT AVG(marks) FROM students);Explanation:
- Inner query: calculates average marks.
- Outer query: displays names of students who scored more than average.
💡 Example – Using EXISTS
SELECT name
FROM students s
WHERE EXISTS (SELECT * FROM attendance a WHERE a.rollno = s.rollno);Explanation:
- Checks whether each student has a record in the attendance table.
🔟 10 Most Expected MCQs – ECET 2026 [SQL Subqueries]
Q1. A subquery is also called a:
A) Subroutine
B) Nested Query
C) Join Query
D) View
Q2. A subquery must be enclosed in:
A) Curly Braces
B) Double Quotes
C) Parentheses
D) Square Brackets
Q3. Which clause can contain a subquery?
A) SELECT
B) FROM
C) WHERE
D) All of the above
Q4. A subquery that returns multiple rows must use:
A) =
B) IN or ANY
C) >
D) BETWEEN
Q5. The subquery executed for every row of the outer query is called:
A) Independent Subquery
B) Correlated Subquery
C) Nested Join
D) View Query
Q6. Which operator is used to test existence of rows in subquery?
A) IN
B) ANY
C) EXISTS
D) ALL
Q7. In a subquery, the inner query is executed:
A) After outer query
B) Before outer query
C) Simultaneously
D) Randomly
Q8. Which of the following is TRUE about subqueries?
A) They cannot return multiple rows
B) They can only be used in SELECT
C) They can be nested multiple times
D) They must return numeric data
Q9. Which is a valid correlated subquery?
A) Subquery independent of outer query
B) Subquery depending on outer query values
C) Subquery with no WHERE condition
D) Subquery using GROUP BY
Q10. Which keyword is used to compare a value to a list returned by a subquery?
A) IN
B) EXISTS
C) LIKE
D) NOT
✅ Answer Key
| Q.No | Answer |
|---|---|
| Q1 | B |
| Q2 | C |
| Q3 | D |
| Q4 | B |
| Q5 | B |
| Q6 | C |
| Q7 | B |
| Q8 | C |
| Q9 | B |
| Q10 | A |
🧠 Explanations
- Q1 → B: Subqueries are also called Nested Queries.
- Q2 → C: Subqueries are written inside parentheses
( ). - Q3 → D: Subqueries can be used in SELECT, FROM, and WHERE clauses.
- Q4 → B: Multiple-row subqueries use
IN,ANY, orALL. - Q5 → B: Correlated subqueries execute once per row of outer query.
- Q6 → C:
EXISTSchecks whether rows exist. - Q7 → B: Inner query executes before the outer query.
- Q8 → C: SQL allows multiple levels of nested subqueries.
- Q9 → B: Correlated subquery depends on outer query.
- Q10 → A:
INis used for matching a value against a list returned by a subquery.
🎯 Why Practice Matters
- Subqueries are frequently asked in ECET DBMS papers.
- Once understood, these are easy to implement.
- Questions are direct from syntax and examples like
AVG,IN, orEXISTS. - Helps in both ECET exams and SQL job interviews.

