GATE / CS ARCHIVE

GATE CSE 1991 / QUESTION 12(a.i)

Parts supplied within Delhi

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

GATE 1991, Q12(a.i) Descriptive
Report issue

SQL & Queries

Question 12(a.i), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Write SQL returning part codes supplied to a Delhi project by a Delhi supplier.
Question 12(a.i), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Write SQL returning part codes supplied to a Delhi project by a Delhi supplier.
Question 12(a.i), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Write SQL returning part codes supplied to a Delhi project by a Delhi supplier.
Tap to enlarge
Answer & solution

Answer: SELECT DISTINCT X.PCODE from the shipment/supplier/project join where both cities are DELHI. (no official key was published)

The shipment relation provides the association among a supplier, a part and a project. Join it to SUPPLIER on SCODE and to PROJECTS on PRCODE. The two city restrictions apply independently to supplier and project, not to PART.CITY.

SELECT DISTINCT X.PCODE
FROM SPPR AS X
JOIN SUPPLIER AS S ON S.SCODE = X.SCODE
JOIN PROJECTS AS P ON P.PRCODE = X.PRCODE
WHERE S.CITY = 'DELHI' AND P.CITY = 'DELHI';

A qualifying shipment is a witness that the part satisfies the request. DISTINCT ensures each code appears once even if multiple suppliers or projects witness it, or several shipment records exist. No join to PART is necessary because the requested code is already present in SPPR, under the usual foreign-key consistency assumption. If parts must also exist despite unenforced references, add JOIN PART AS T ON T.PCODE=X.PCODE. SQL string comparison follows the database's collation; DELHI is the source's city literal.

Original paper, page 7