Subqueries & CTEs · Question 15 · Medium
In the query below, how is the inner query logically evaluated?
SELECT name
FROM Faculty f
WHERE salary > (SELECT AVG(salary)
FROM Faculty g
WHERE g.dept = f.dept);
- Exactly once, and the single result is reused for every outer row
- Once for every pair of rows from f and g
- Once for each row of the outer query, using that row's dept
- After the outer query has finished, to filter its final result
Answer and explanation
Answer: C. Once for each row of the outer query, using that row's dept
Explanation: The inner query refers to f.dept from the outer query, so it is a correlated subquery. Its value depends on the current outer row and is logically worked out again for each one.
Previous: Table Marks: student | subject | score Kavya | Maths | 88 Kavya | Physics | 70… · Next: Table Marks: student | subject | score Kavya | Maths | 88 Kavya | Physics | 70…
Practise subqueries & ctes
Try a fresh set of subqueries & ctes questions with an explanation after every answer, free and without signing up: Subqueries & CTEs practice. Or sit a full placement mock test.
More subqueries & ctes questions
- Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |…
- Table Members: mid | name 1 | Geeta 2 | Hari 3 | Imran 4 | Jaya Table Loans…
- Table Marks: student | subject | score Kavya | Maths | 88 Kavya | Physics | 70…
- Table Marks: student | subject | score Kavya | Maths | 88 Kavya | Physics | 70…
- Table Marks: student | subject | score Kavya | Maths | 88 Kavya | Physics | 70…
- Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |…
- Table Members: mid | name 1 | Geeta 2 | Hari 3 | Imran 4 | Jaya Table Loans…
- Tables Members(mid, name) and Loans(loan_id, mid, book) are given, and…
More sql practice
Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions · SELECT, WHERE & ORDER BY · SQL Joins
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge