CS FundamentalsVery hardGATE 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 sname FROM Stu s
WHERE NOT EXISTS (
SELECT cid FROM Takes p
WHERE p.sid = 1
AND NOT EXISTS (SELECT * FROM Takes t
WHERE t.sid = s.sid AND t.cid = p.cid))
ORDER BY sname;- A. Om
- B. Om, Pia, Raj
- C. Om, Raj
- D. Om, Pia
Correct answer: A. Om
This is relational division: students who took every course that student 1 (Om) took, i.e. both C1 and C2. Pia lacks C2 and Raj lacks C1, so only Om remains.
More DBMS and SQL questions
- Relations R (1000 blocks) and S (500 blocks) are joined with block nested-loop join using M = 22 buffer blocks (M − 2 for the outer…
- T1: W1(A), W1(B) and T2: R2(A), R2(B). Of all 6 interleavings that keep each transaction's own order, how many are conflict serializable?
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- 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…