Over 10 years we helping companies reach their financial and branding goals. Onum is a values-driven SEO agency dedicated.

CONTACTS
ECET 2026 CSE

Day 55 – ECET 2026 Evening Section: DBMS – SQL Subqueries & Nested Queries

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

  1. Single-row Subquery:
    • Returns only one value.
      Example:
SELECT name 
FROM students 
WHERE marks = (SELECT MAX(marks) FROM students);
  1. Multiple-row Subquery:
    • Returns multiple rows.
      Example:
SELECT name 
FROM students 
WHERE marks IN (SELECT marks FROM students WHERE grade = 'A');
  1. Multiple-column Subquery:
    • Returns multiple columns.
      Example:
SELECT name 
FROM students 
WHERE (marks, grade) IN (SELECT marks, grade FROM toppers);
  1. Correlated Subquery:
    • Inner query depends on outer query for its values.
      Example:
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

OperatorDescriptionUsed in
=Equal toSingle-row subquery
INMatch any value from subqueryMultiple-row subquery
ANYCompare to each value from subqueryMultiple-row subquery
ALLCompare to all values from subqueryMultiple-row subquery
EXISTSCheck if subquery returns any rowsCorrelated subquery

🔹 Formula – General Representation of a Subquery

A subquery can be represented as:

 Q_{main} = Q_{outer}(Q_{inner})

Where:

  •  Q_{inner} = Subquery providing intermediate results.
  •  Q_{outer} = 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.NoAnswer
Q1B
Q2C
Q3D
Q4B
Q5B
Q6C
Q7B
Q8C
Q9B
Q10A

🧠 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, or ALL.
  • Q5 → B: Correlated subqueries execute once per row of outer query.
  • Q6 → C: EXISTS checks 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: IN is 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, or EXISTS.
  • Helps in both ECET exams and SQL job interviews.

📲 Join Our ECET Prep Community on WhatsApp

👉 Join WhatsApp Group – Click Here

Leave a comment

Your email address will not be published. Required fields are marked *