Subqueries & CTEs · Question 2 · Easy
Subqueries & CTEs question 2
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
Which member names does this query return?
SELECT name
FROM Members
WHERE mid IN (SELECT mid FROM Loans)
ORDER BY name;
- Geeta; Imran
- Geeta; Geeta; Imran
- Hari; Jaya
- Geeta; Hari; Imran; Jaya
Answer and explanation
Answer: A. Geeta; Imran
Explanation: The subquery returns 1, 1, 3 and NULL. IN only tests membership, so Geeta appears once even though she has two loans, and the NULL matches nobody.
Previous: Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |… · Next: A subquery that returns exactly one row with one column, so it can be used…
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 |…
- A subquery that returns exactly one row with one column, so it can be used…
- Table Faculty: fid | name | dept | salary 1 | Anand | CSE | 90000 2 | Bhavna |…
- 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 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 |…
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