CS FundamentalsHardGATE CS · SQL
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 COUNT(*) FROM Staff e LEFT JOIN Staff b ON e.boss = b.id WHERE b.dept = 'Ops' OR b.id IS NULL;
- A. 1
- B. 6
- C. 3
- D. 4
Correct answer: D. 4
Bala and Chitra report to Anu (Ops) and Farid to Bala (Ops); Anu has no boss, so the outer join pads b with NULLs and b.id IS NULL keeps her. Dev and Esha report to Chitra (Tech). Total 4.
More DBMS and SQL questions
- A buffer manager uses STEAL (uncommitted pages may be written to disk) and NO-FORCE (committed pages need not be written at commit). What…
- 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'…
- A file of 10,000 records is physically ordered on the non-key field dept, which has 500 distinct values. A clustering index on dept has…
- Which expression is equivalent to R ÷ S, where R(A, B) and S(B)?
- Which is a correct reason why testing a schedule for VIEW serializability is rarely done in practice?
- 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'…