GATE / CS ARCHIVE

GATE CSE 2009 / QUESTION 55

Nested NOT IN supplier query

Database Management Systems · SQL & Queries · Full GATE CSE 2009 paper

GATE 2009, Q55 2 marks · MCQ
Report issue

SQL & Queries

Question 55, GATE 2009: Schema Suppliers(sid key, sname, city, street), Parts(pid key, pname, color), Catalog(sid, pid composite key, cost). Query SELECT S.sname FROM Suppliers S WHERE S.sid NOT IN(SELECT C.sid FROM Catalog C WHERE C.pid NOT IN(SELECT P.pid FROM Parts P WHERE P.color<>blue)). Relations nonempty. Options suppliers who A supplied a non-blue part; B have not supplied a non-blue part; C supplied only blue parts; D have not supplied only blue parts. Preserve SQL-null/referential-integrity and wording qualifications.
Question 55, GATE 2009: Schema Suppliers(sid key, sname, city, street), Parts(pid key, pname, color), Catalog(sid, pid composite key, cost). Query SELECT S.sname FROM Suppliers S WHERE S.sid NOT IN(SELECT C.sid FROM Catalog C WHERE C.pid NOT IN(SELECT P.pid FROM Parts P WHERE P.color<>blue)). Relations nonempty. Options suppliers who A supplied a non-blue part; B have not supplied a non-blue part; C supplied only blue parts; D have not supplied only blue parts. Preserve SQL-null/referential-integrity and wording qualifications.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

The innermost query finds non-blue part IDs. The middle query finds supplier IDs for catalog rows whose part is not in that set, i.e. suppliers of a blue part under the intended referential-integrity and non-NULL color assumptions. The outer NOT IN therefore returns names of suppliers who supply no blue parts, including suppliers with no catalog rows. The intended option is D, but its printed wording is imprecise: “have not supplied only blue parts” logically also includes mixed-color suppliers, whereas the SQL excludes them. A asks for any non-blue supply and also includes mixed suppliers; B and C concern suppliers with no non-blue supply / only blue supply, the opposite condition. Thus no option states the exact result under a literal reading. Do not present D as an officially verified or exact semantic equivalence.

Read the nested NOT IN clauses from inside out. First collect non-blue part IDs; next collect suppliers with a catalog part outside that set, meaning a blue part under non-null referential-integrity assumptions; finally exclude those suppliers. The result is suppliers with no blue supply, including suppliers with no catalog row. A supplier of both blue and red is excluded. That mixed-supply example demonstrates why printed D is not literally equivalent to the SQL despite being the intended choice. The discrepancy is semantic, not a reason to invent an official key.

Original paper, page 13