CS FundamentalsVery hardProduct company interview · GATE level
Table Proj(pid, lead, dept, budget, parent) rows: (1, 'Uma', 'R&D', 900, NULL), (2, 'Vik', 'R&D', 400, 1), (3, 'Uma', 'Ops', NULL, 1), (4, 'Wen', 'Ops', 400, 2), (5, 'Xia', NULL, 650, 2), (6, 'Vik', 'Ops', 250, 4), (7, 'Yash', 'R&D', NULL, NULL), (8, 'Wen', NULL, 100, 6). What does this query return under standard SQL semantics?
Table Proj(pid, lead, dept, budget, parent) rows: (1, 'Uma', 'R&D', 900, NULL), (2, 'Vik', 'R&D', 400, 1), (3, 'Uma', 'Ops', NULL, 1), (4, 'Wen', 'Ops', 400, 2), (5, 'Xia', NULL, 650, 2), (6, 'Vik', 'Ops', 250, 4), (7, 'Yash', 'R&D', NULL, NULL), (8, 'Wen', NULL, 100, 6).
What does this query return under standard SQL semantics?
SELECT COUNT(*) FROM Proj WHERE budget > ALL (SELECT budget FROM Proj WHERE dept = 'HR');
- A. 8
- B. 6
- C. 0
- D. The query fails with an error
Correct answer: A. 8
No project belongs to 'HR', so the subquery returns an empty set. A comparison with ALL over an empty set is TRUE for every row - there is no value that could make it fail - and this holds even for the two rows whose budget is NULL, because no comparison is ever carried out. All 8 rows are counted. The answer 6 assumes the NULL budgets drop out; 0 would be the result of > ANY, which is FALSE over an empty set.
More DBMS and SQL questions
- Table Proj(pid, lead, dept, budget, parent) rows: (1, 'Uma', 'R&D', 900, NULL), (2, 'Vik', 'R&D', 400, 1), (3, 'Uma', 'Ops', NULL, 1), (4…
- R(A, B, C, D, E, F) has functional dependencies AB → C, C → A, C → D, D → B and E → F. How many candidate keys does R have, and what is…
- R(A, B, C, D, E) has functional dependencies AB → C, C → D, D → E and E → A. Which statement is correct?
- The set F = { A → B, BC → D, AC → D, D → E, CE → A } holds on R(A, B, C, D, E). Which of the following dependencies is redundant, i.e. can…
- R(A, B, C, D) with functional dependencies A → B, B → C and C → D is decomposed into R1(A, B), R2(B, C) and R3(A, D). Which statement…
- R(A, B, C, D, E) has functional dependencies A → B, BC → D, D → AE and E → C. How many of the following dependencies are logically…