CS FundamentalsModerateGATE CS · SQL

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 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 COUNT(*) FROM Takes a JOIN Takes b
  ON a.cid = b.cid AND a.sid < b.sid;
  1. A. 5
  2. B. 8
  3. C. 3
  4. D. 4

Correct answer: D. 4

C1 is taken by sids 1, 2, 5 → 3 pairs; C2 by 1 and 3 → 1 pair; C3 by one student. a.sid < b.sid counts each unordered pair once: 4.

More DBMS and SQL questions

Exams that ask this topic