CS FundamentalsHardGATE CS · Product-company placement
Table T(x) has rows (1), (2), (3) and table U(y) has rows (2), (NULL). What do these two queries return? Q1: SELECT COUNT(*) FROM T WHERE x NOT IN (SELECT y FROM U); Q2: SELECT COUNT(*) FROM T WHERE NOT EXISTS (SELECT 1 FROM U WHERE U.y = T.x);
- A. Q1 = 2, Q2 = 2
- B. Q1 = 0, Q2 = 2
- C. Q1 = 0, Q2 = 0
- D. Q1 = 2, Q2 = 0
Correct answer: B. Q1 = 0, Q2 = 2
x NOT IN (2, NULL) means x <> 2 AND x <> NULL; the second part is UNKNOWN, so no row qualifies and Q1 = 0. NOT EXISTS only asks whether a matching row exists, so 1 and 3 qualify and Q2 = 2.
More DBMS and SQL questions
- Cust(cid, city) has rows (1, 'Pune'), (2, 'Delhi'), (3, NULL), (4, 'Pune'). Ord(oid, cid, amt) has rows (10, 1, 500), (11, 1, NULL), (12…
- Ord(oid, cid, amt) has rows (10, 1, 500), (11, 1, NULL), (12, 2, 300), (13, NULL, 200), (14, 5, 100). What does SELECT COUNT()…
- Player(pid, team, runs) has rows (1, 'A', 50), (2, 'A', 70), (3, 'A', 70), (4, 'B', 40), (5, 'B', NULL), (6, 'B', 90), (7, 'C', NULL). For…
- Pay(d, amt) has rows (1, 10), (2, 20), (2, 30), (3, 40). For the row (2, 20), what value does SUM(amt) OVER (ORDER BY d) give?
- What does this query return? SELECT CASE NULL WHEN NULL THEN 'eq' ELSE 'ne' END, CASE WHEN NULL IS NULL THEN 'eq' ELSE 'ne' END;
- Skill(emp, sk) has rows (r, sql), (r, py), (r, go), (s, sql), (s, py), (t, sql), (t, go), (t, py), (t, c). Req(sk) has rows (sql), (py)…