GATE / CS ARCHIVE

GATE CSE 2020 / QUESTION 13

GATE CSE 2020 Q13

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

GATE 2020, Q13 1 mark · MCQ
Report issue

SQL & Queries

Question 13, GATE 2020: Catalogue(sno,pno,cost) has rows (S1,P1,150),(S1,P2,50),(S1,P3,100),(S2,P4,200),(S2,P5,250),(S3,P1,250),(S3,P2,150),(S3,P5,300),(S3,P4,250), primary key (sno,pno). Suppliers has primary key sno and one row each: S1/Royal furniture/Delhi, S2/Balaji furniture/Bangalore, S3/Premium furniture/Chennai. Parts has primary key pno: P1/Table/Wood, P2/Chair/Wood, P3/Table/Steel, P4/Almirah/Steel, P5/Almirah/Wood. Count rows returned by:
SELECT s.sno, s.sname FROM Suppliers s, Catalogue c
WHERE s.sno=c.sno AND cost >
(SELECT AVG(cost) FROM Catalogue WHERE pno='P4' GROUP BY pno);
Options: A 4; B 5; C 0; D 2.
Question 13, GATE 2020: Catalogue(sno,pno,cost) has rows (S1,P1,150),(S1,P2,50),(S1,P3,100),(S2,P4,200),(S2,P5,250),(S3,P1,250),(S3,P2,150),(S3,P5,300),(S3,P4,250), primary key (sno,pno). Suppliers has primary key sno and one row each: S1/Royal furniture/Delhi, S2/Balaji furniture/Bangalore, S3/Premium furniture/Chennai. Parts has primary key pno: P1/Table/Wood, P2/Chair/Wood, P3/Table/Steel, P4/Almirah/Steel, P5/Almirah/Wood. Count rows returned by:
SELECT s.sno, s.sname FROM Suppliers s, Catalogue c
WHERE s.sno=c.sno AND cost >
(SELECT AVG(cost) FROM Catalogue WHERE pno='P4' GROUP BY pno);
Options: A 4; B 5; C 0; D 2.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Worked explanation

Evaluate the uncorrelated scalar subquery once. Filtering pno=P4 leaves prices 200 and 250, so its one group has average 225. Apply the outer strict comparison to every Catalogue row; prices 250,250,300,250 survive. The supplier primary key makes each surviving row join with exactly one supplier row, so the join neither loses nor multiplies them. Projection returns S2 once and S3 three times. SQL SELECT uses bag semantics unless DISTINCT is requested; it does not automatically collapse those repeated S3 names. The Parts table is not referenced by this query and cannot affect the count.

Derivation and answer

The P4 rows have costs 200 and 250, so the subquery returns 225. Catalogue costs greater than 225 occur at(S2, P5),(S3, P1),(S3, P5),(S3, P4): four rows. The supplier join preserves all four and SELECT has no DISTINCT, so repeated S3 output rows remain. Answer 4, A.

Original paper, page 7 · Answer key