CS FundamentalsModerateTCS Digital · Infosys SP · GATE CS

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 COUNT(*) FROM Takes t
WHERE t.sid NOT IN (SELECT sid FROM Stu)
   OR t.marks IS NULL;
  1. A. 2
  2. B. 0
  3. C. 3
  4. D. 1

Correct answer: A. 2

Stu.sid has no NULLs, so NOT IN works normally: only sid 5 (an orphan row) is missing. Om's C2 row has NULL marks. Two rows.

More DBMS and SQL questions

Exams that ask this topic