CS FundamentalsHardGATE CS (PYQ pattern)

S1(s): a, b, c, d. C1(c): x, y. T1(s, c): (a,x), (a,y), (b,x), (c,y), (c,x), (c,y). How many rows does SELECT s FROM S1 WHERE NOT EXISTS (SELECT 1 FROM C1 WHERE NOT EXISTS (SELECT 1 FROM T1 WHERE T1.s = S1.s AND T1.c = C1.c)) return?

  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 4

Correct answer: B. 2

This is the double-NOT-EXISTS form of division: s qualifies if there is no course c in C1 that s has not taken. a and c have both x and y (c has y twice), b lacks y, and d has no rows at all so every course is missing for d. Result = 2 rows (a and c).

More DBMS and SQL questions

Exams that ask this topic