Subqueries & CTEs · Question 19 · Hard
Subqueries & CTEs question 19
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. What does this query return?
SELECT COUNT(*)
FROM Loans
WHERE mid NOT IN (SELECT mid FROM Members
WHERE name = 'Geeta');
- 0
- 1
- 2
- 3
Answer and explanation
Answer: B. 1
Explanation: The subquery returns just 1. Loans 1 and 2 have mid 1, so NOT IN is false; loan 3 has mid 3, so it is true. For loan 4, NULL NOT IN (1) is unknown, so that row is not counted either.
Previous: Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |… · Next: Tables Members(mid, name) and Loans(loan_id, mid, book) are given, and…
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 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 |…
- 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