Question discussion

What is the output of the following SQL statements?CREATE TABLE s(id INT, name TEXT); CREATE TABLE c(id INT); CREATE TABLE e(sid INT, cid I…

1723Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following SQL statements?

CREATE TABLE s(id INT, name TEXT);
CREATE TABLE c(id INT);
CREATE TABLE e(sid INT, cid INT);
INSERT INTO s VALUES (1,'Asha'),(2,'Ben'),(3,'Chen');
INSERT INTO c VALUES (10),(20);
INSERT INTO e VALUES (1,10),(1,20),(2,10),(3,10),(3,20);
SELECT name FROM s WHERE NOT EXISTS (SELECT 1 FROM c WHERE NOT EXISTS
  (SELECT 1 FROM e WHERE e.sid = s.id AND e.cid = c.id)) ORDER BY name;
  • AAsha, Chen
  • BAsha, Ben, Chen
  • CBen
  • DAsha
Correct answer: A

Explanation

The double NOT EXISTS pattern implements division: it returns the students enrolled in every course, and only Asha and Chen are enrolled in both courses 10 and 20.

Discussion 0

Nobody has replied yet. Start the discussion!