CS FundamentalsVery hardTCS Digital · Infosys SP · GATE CS
Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What does this query return?
Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2).
What does this query return?
SELECT s.name FROM Staff s JOIN (SELECT dept, MAX(pay) AS m FROM Staff GROUP BY dept) t ON s.dept = t.dept AND s.pay = t.m ORDER BY s.name;
- A. Bala, Chitra, Esha, Farid
- B. Bala, Chitra, Farid
- C. Bala, Chitra
- D. Chitra, Farid
Correct answer: B. Bala, Chitra, Farid
Group maxima: Ops 55, Tech 70, NULL-dept group 35. Joining back on s.dept = t.dept fails for Esha because NULL = NULL is unknown, so the result is Bala, Chitra and Farid (both 70s tie).
More DBMS and SQL questions
- R has 2000 tuples in 100 blocks and S has 10000 tuples in 400 blocks. With only enough memory for one block of each relation, how many…
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- Table Sale(id, rep, region, amt) rows: (1, 'Ira', 'N', 100), (2, 'Jai', 'S', 250), (3, 'Ira', 'S', NULL), (4, 'Kim', 'N', 300), (5, 'Jai'…
- Consider the schedule R2(B), R3(A), W3(A), R2(A), W2(B), R1(B), R1(A). Which statement is correct?
- The system crashes after the last record of this log (immediate database modification; <Ti, X> denotes an update with old and new values…
- R(A, B, C, D, E) has functional dependencies CE → A, B → AC, BE → CD, DE → B. How many superkeys does R have?