Subqueries & CTEs · Question 8 · Medium
Subqueries & CTEs question 8
Table Members:
mid | name
1 | Geeta
2 | Hari
3 | Imran
4 | Jaya
Table Loans:
loan_id | mid | book
1 | 1 | Wings
2 | 1 | Malgudi
3 | 3 | Godan
4 | NULL | Ignited
One loan has no member recorded. Which names does this query return?
SELECT name
FROM Members m
WHERE NOT EXISTS (SELECT 1 FROM Loans l
WHERE l.mid = m.mid)
ORDER BY name;
- No rows
- Geeta; Imran
- Hari; Jaya
- Geeta; Hari; Imran; Jaya
Answer and explanation
Answer: C. Hari; Jaya
Explanation: For each member the subquery looks for a loan with the same mid. None exists for Hari and Jaya, so NOT EXISTS is true for them. The loan with a NULL mid simply matches nobody; it does not empty the result as it would with NOT IN.
Previous: Table Members: mid | name 1 | Geeta 2 | Hari 3 | Imran 4 | Jaya Table Loans… · Next: Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |…
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
- Which keyword starts a common table expression (CTE), a named result that the…
- 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 Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |…
- Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |…
- Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |…
- 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…
- In the query below, how is the inner query logically evaluated?
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