CS FundamentalsHardTCS 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). How many rows 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).
How many rows does this query return?
SELECT dept, COUNT(*) FROM Staff GROUP BY dept UNION ALL SELECT dept, COUNT(*) FROM Staff WHERE pay > 50 GROUP BY dept;
- A. 3
- B. 5
- C. 6
- D. 4
Correct answer: B. 5
The first query gives 3 groups (Ops, Tech, NULL). The second keeps Bala, Chitra, Farid and gives 2 groups (Ops, Tech). UNION ALL keeps all 5 rows.
More DBMS and SQL questions
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- TS(T1) = 20, TS(T2) = 5, TS(T3) = 25; all read/write timestamps start at 0. Under basic timestamp ordering with Thomas's write rule, which…
- R(A, B, C, D, E, F) has functional dependencies D → BF, AE → B, F → CD, DE → C. How many prime attributes does R have?
- R(A, B, C, D, E) has the set of functional dependencies Σ = {CE → D, C → AD, AE → CD}. Which of the following FDs is NOT in Σ⁺ (not…
- R(A, B, C, D) has functional dependencies D → BC, B → C, C → BD. What is the highest normal form R satisfies?
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…