Subqueries & CTEs · Question 16 · Hard
Subqueries & CTEs question 16
Table Marks:
student | subject | score
Kavya | Maths | 88
Kavya | Physics | 70
Lokesh | Maths | 92
Lokesh | Physics | 65
Mitali | Maths | 75
Mitali | Physics | 95
Which students does this query return?
SELECT DISTINCT student
FROM Marks m
WHERE NOT EXISTS (SELECT 1 FROM Marks x
WHERE x.student = m.student
AND x.score < 70)
ORDER BY student;
- Kavya; Lokesh; Mitali
- Mitali
- Lokesh
- Kavya; Mitali
Answer and explanation
Answer: D. Kavya; Mitali
Explanation: NOT EXISTS keeps a student only if that student has no score below 70 in any subject. Lokesh has 65 in Physics, so both his rows are rejected. Kavya's 70 is not below 70, so she stays.
Previous: In the query below, how is the inner query logically evaluated? · 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 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?
- 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