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?
- A. 1
- B. 2
- C. 3
- 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
- Tables T(x): 1, 2, 3 and U(y) is EMPTY. In standard SQL, what does SELECT COUNT() FROM T WHERE x > ALL (SELECT y FROM U) return, and what…
- Table V(id, v): (1,40), (2,10), (3,40), (4,30), (5,20), (6,30). What are the ids returned, in order, by SELECT id FROM V ORDER BY v DESC…
- P1(id, name, dept): (1,a,10), (2,b,20), (3,c,10). P2(id, name, city): (1,a,X), (2,z,Y), (4,d,Z). How many rows does SELECT FROM P1 NATURAL…
- DP(d): 1, 2, 3. EP(e, d): (1,1), (2,1), (3,1), (4,3). For SELECT DP.d, COUNT() AS a, COUNT(EP.e) AS b FROM DP LEFT JOIN EP ON DP.d = EP.d…
- SL(r, q, amt): (N,Q1,10), (N,Q2,20), (S,Q1,5), (S,Q1,15), (S,Q2,NULL), (E,Q2,7). The query SELECT r, SUM(CASE WHEN q = 'Q1' THEN amt END)…
- Schedule: R1(A), W2(A), R3(B), R2(B), W3(C), W1(C), R4(D). How many different serial orders of T1, T2, T3, T4 are conflict-equivalent to it?