CS FundamentalsVery hardGATE CS · Amazon/Microsoft SDE MCQ
Table Emp(eid, name, mgr, dept, sal) rows: (1, 'Aru', NULL, 'D1', 90), (2, 'Bin', 1, 'D1', 60), (3, 'Cy', 1, 'D2', 70), (4, 'Dev', 2, 'D1', 60), (5, 'Eli', 2, 'D2', 40), (6, 'Fay', 3, NULL, 75), (7, 'Gus', 4, 'D1', 30). mgr refers to eid. What does this query return? SELECT COUNT(*) FROM Emp e LEFT JOIN Emp m ON e.mgr = m.eid WHERE m.dept = 'D1' OR m.dept IS NULL;
- A. 7
- B. 1
- C. 3
- D. 6
Correct answer: D. 6
Five employees (Bin, Cy, Dev, Eli, Gus) have a manager in D1, and Aru (no manager) survives because the left join pads m with NULLs: 6. 7 wrongly keeps Fay by reading her own NULL dept (her manager Cy is in D2); 3 counts distinct D1 managers and 1 only the padded row.
More DBMS and SQL questions
- Table Emp(eid, name, mgr, dept, sal) rows: (1, 'Aru', NULL, 'D1', 90), (2, 'Bin', 1, 'D1', 60), (3, 'Cy', 1, 'D2', 70), (4, 'Dev', 2…
- Table Emp(eid, name, mgr, dept, sal) rows: (1, 'Aru', NULL, 'D1', 90), (2, 'Bin', 1, 'D1', 60), (3, 'Cy', 1, 'D2', 70), (4, 'Dev', 2…
- Table Emp(eid, name, mgr, dept, sal) rows: (1, 'Aru', NULL, 'D1', 90), (2, 'Bin', 1, 'D1', 60), (3, 'Cy', 1, 'D2', 70), (4, 'Dev', 2…
- Table Emp(eid, name, mgr, dept, sal) rows: (1, 'Aru', NULL, 'D1', 90), (2, 'Bin', 1, 'D1', 60), (3, 'Cy', 1, 'D2', 70), (4, 'Dev', 2…
- A B+ tree index uses 2048-byte blocks, 16-byte search keys, 8-byte block pointers and 10-byte record pointers; a leaf also holds one…
- A file of 12,000 blocks is sorted by external merge sort with 25 buffer blocks: the run-creation pass makes runs of 25 blocks, and each…