CS FundamentalsHardGATE CS (PYQ pattern)
T(x) holds 1, 2, 3, 4, 5, 6, NULL and U(y) holds 2, 4, NULL. Let a, b, c be the row counts of (a) SELECT * FROM T WHERE x NOT IN (SELECT y FROM U) (b) SELECT * FROM T WHERE NOT EXISTS (SELECT 1 FROM U WHERE U.y = T.x) (c) SELECT * FROM T WHERE x NOT IN (SELECT y FROM U WHERE y IS NOT NULL) under standard SQL three-valued logic. What is (a, b, c)?
- A. (0, 5, 4)
- B. (4, 5, 4)
- C. (0, 4, 4)
- D. (4, 4, 5)
Correct answer: A. (0, 5, 4)
(a) U contains NULL, so x NOT IN (2, 4, NULL) is never TRUE: 0 rows. (b) NOT EXISTS only asks whether an equal row exists; 1, 3, 5, 6 and the NULL row (NULL = anything is not TRUE) all qualify: 5. (c) With NULL filtered out, 1, 3, 5, 6 qualify, but x = NULL gives NULL NOT IN (2, 4) = UNKNOWN: 4.
More DBMS and SQL questions
- Table S(id, v): (1,10), (2,20), (3,20), (4,30), (5,30), (6,40). SELECT SUM(v) OVER (ORDER BY v) AS s FROM S ORDER BY id; What is the sum…
- Table P(n, s): (a,90), (b,85), (c,85), (d,70), (e,70), (f,70), (g,60). A query computes r = RANK() OVER (ORDER BY s DESC) and d =…
- Table W(id, dept, sal): (1,A,50), (2,A,70), (3,A,90), (4,B,40), (5,B,40), (6,C,100), (7,C,20), (8,C,NULL), (9,D,NULL). SELECT COUNT() FROM…
- A1(x) holds 1, 1, 1, 2, 2, 3, NULL, NULL and B1(x) holds 1, 2, 2, 2, NULL, 4. Using the standard bag semantics (a value occurring m times…
- Tables ST(s, c) with rows (p,DB), (p,OS), (p,CN), (q,DB), (q,OS), (r,DB), (r,OS), (r,CN), (r,AI), (s,CN), (s,OS), (s,DB), (s,DB) and…
- Edge table G(a, b): (1,2), (2,3), (3,1), (3,4), (4,5), (6,7). The recursive query WITH RECURSIVE R(x,y) AS (SELECT a,b FROM G UNION SELECT…