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;
  1. Kavya; Lokesh; Mitali
  2. Mitali
  3. Lokesh
  4. 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

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