Skip to content
GATEiit

GATE CSE 2020 Q23: Rows returned by a join with a nested AVG subquery

Question

Consider a relational database containing the following schemas.

Catalogue (primary key: sno, pno)
snopnocost
S1P1150
S1P250
S1P3100
S2P4200
S2P5250
S3P1250
S3P2150
S3P5300
S3P4250
Suppliers (primary key: sno)
snosnamelocation
S1M/s Royal furnitureDelhi
S2M/s Balaji furnitureBangalore
S3M/s Premium furnitureChennai
Parts (primary key: pno)
pnopnamepart_spec
P1TableWood
P2ChairWood
P3TableSteel
P4AlmirahSteel
P5AlmirahWood
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);

The primary key of each table is indicated by underlining the constituent fields (shown here in each caption).

The number of rows returned by the above SQL query is

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 1/3 mark in GATE.
Show answer and explanation

Answer: A (official GATE 2020 final answer key)

Concept used: Evaluate the scalar subquery first, then count joined rows that pass the filter (duplicates are kept without DISTINCT).

First step: The subquery averages the P4 costs: (200+250)/2=225(200 + 250)/2 = 225. Count Catalogue rows with cost above 225.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2020 CS question paper and final answer key, organised by IIT Delhi. Question paper · Answer key