CS FundamentalsHardGATE CS · SQL
Table Stu(sid, sname) rows: (1, 'Om'), (2, 'Pia'), (3, 'Raj'), (4, 'Sia'). Table Takes(sid, cid, marks) rows: (1, 'C1', 80), (1, 'C2', NULL), (2, 'C1', 65), (3, 'C2', 90), (3, 'C3', 75), (5, 'C1', 50). What does this query return?
Table Stu(sid, sname) rows: (1, 'Om'), (2, 'Pia'), (3, 'Raj'), (4, 'Sia').
Table Takes(sid, cid, marks) rows: (1, 'C1', 80), (1, 'C2', NULL), (2, 'C1', 65), (3, 'C2', 90), (3, 'C3', 75), (5, 'C1', 50).
What does this query return?
SELECT s.sname, COUNT(*), COUNT(t.cid) FROM Stu s LEFT JOIN Takes t ON s.sid = t.sid WHERE s.sname = 'Sia' GROUP BY s.sname;
- A. Sia, 1, 0
- B. No rows (empty result)
- C. Sia, 1, 1
- D. Sia, 0, 0
Correct answer: A. Sia, 1, 0
Sia has no Takes rows, so the LEFT JOIN keeps one row padded with NULLs. COUNT(*) counts that row (1); COUNT(t.cid) skips the NULL (0).
More DBMS and SQL questions
- Which set of relational algebra operators is a complete (minimal) basis from which the others can be expressed?
- A B-tree (not B+ tree) stores a record pointer with every key in every node. With 1024-byte blocks, 9-byte keys, 6-byte tree pointers and…
- Two transactions each read X = 100. T1 sets X = X − 30 and commits; then T2 sets X = X + 50 and commits. The final value is 150. Which…
- Classify the schedule R2(B), W1(A), W2(A), W3(A), R1(B), W1(B), R3(A), R3(B).
- Under basic two-phase locking, a conflict-serializable schedule is equivalent to the serial schedule that orders transactions by their:
- A weak entity set Dependent (partial key dname) is owned by Employee (key eid) through the identifying relationship HasDep. Which table…