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?
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?
SELECT COUNT(*) FROM Proj a JOIN Proj b ON a.budget = b.budget;
- A. 12
- B. 6
- C. 8
- D. 10
Correct answer: C. 8
Each row joins with every row that has an equal budget, including itself. Budgets 900, 650, 250 and 100 occur once, giving 1 pair each. Budget 400 occurs twice (pids 2 and 4), giving 2 x 2 = 4 pairs. The two NULL budgets match nothing, not even themselves, because NULL = NULL is unknown. Total 4 + 4 = 8. The answer 6 counts each non-NULL row once; 12 lets the two NULL rows pair up with each other (another 4 pairs).
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…
- 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…
- 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…