CS FundamentalsHardGATE CS (PYQ pattern)
Table T(x) holds the values 1, 2, 3, NULL and table U(y) holds 2, NULL. Let Q1 = SELECT COUNT(*) FROM T WHERE x NOT IN (SELECT y FROM U); and Q2 = SELECT COUNT(*) FROM T WHERE NOT EXISTS (SELECT 1 FROM U WHERE U.y = T.x); The results of Q1 and Q2 are:
- A. 0 and 3
- B. 2 and 3
- C. 2 and 2
- D. 3 and 3
Correct answer: A. 0 and 3
x NOT IN (2, NULL) expands to x <> 2 AND x <> NULL, which is never TRUE (it is FALSE or UNKNOWN), so Q1 = 0. NOT EXISTS only checks for matching rows, and U.y = T.x matches only x = 2, so rows 1, 3 and NULL qualify: Q2 = 3.
More DBMS and SQL questions
- DEPT(d, name) has rows (10,A), (20,B), (30,C), (40,D) and EMP(id, dept) has 3 employees in dept 10, 2 in dept 20, 1 in dept 30 and none in…
- EMP has salaries 300, 200, 200, 200, 150, 100 for six employees. Let QR select employees whose RANK() OVER (ORDER BY sal DESC) equals 3…
- R(A, B, C, D, E) has the functional dependencies A → B, BC → D, D → E and E → A. The number of candidate keys of R and its highest normal…
- Consider the schedule S: r1(A) r3(B) r2(C) w2(A) r4(C) w4(B) r1(D) r3(D), where ri/wi is a read/write by transaction Ti. How many distinct…
- A B+ tree on 8-byte keys uses 4096-byte blocks. An internal node holds p tree pointers (8 bytes each) and p − 1 keys. A leaf holds q (key…
- E(id, dept) = (1, 10), (2, 10), (3, 20), (4, 30), (5, NULL), (6, 20), (7, 40) and D(did, loc) = (10, X), (20, Y), (20, X), (30, Y), (50…