GateAI
SQL

GATE CSE 2020 · Q13

MCQ1 markMedium

Time

Consider a relational database containing the following schemas. The primary key of each table is indicated by underlining the constituent fields.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 number of rows returned by the above SQL query is

GATE CSE 2020 Q13 diagram 1
GATE CSE 2020 Q13 diagram 2
GATE CSE 2020 Q13 diagram 3

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) 4

SQL

To find the number of rows returned by the SQL query, we evaluate it step-by-step:

  1. Subquery Evaluation: ```sql SELECT AVG (cost) FROM Catalogue WHERE pno = 'P4'GROUP BY pno;``` From the Catalogue table, the tuples with pno=’P4’\text{pno} = \text{'P4'} are:

    • (S2,P4,200)(\text{S2}, \text{P4}, 200)

    • (S3,P4,250)(\text{S3}, \text{P4}, 250)

    The average cost is:

    AVG(cost)=200+2502=225\text{AVG(cost)} = \frac{200 + 250}{2} = 225
  2. Outer Query Condition: ```sql WHERE s.sno = c.sno AND cost > 225 ``` We find all rows in Catalogue where cost>225\text{cost} > 225:

    • Row 5: (S2,P5,250)(\text{S2}, \text{P5}, 250)

    • Row 6: (S3,P1,250)(\text{S3}, \text{P1}, 250)

    • Row 8: (S3,P5,300)(\text{S3}, \text{P5}, 300)

    • Row 9: (S3,P4,250)(\text{S3}, \text{P4}, 250)

  3. Join and Projection: Joining these 4 rows with the Suppliers table on s.sno=c.sno\text{s.sno} = \text{c.sno} gives:

    • (S2,M/s Balaji furniture)(\text{S2}, \text{M/s Balaji furniture})

    • (S3,M/s Premium furniture)(\text{S3}, \text{M/s Premium furniture})

    • (S3,M/s Premium furniture)(\text{S3}, \text{M/s Premium furniture})

    • (S3,M/s Premium furniture)(\text{S3}, \text{M/s Premium furniture})

    Since DISTINCT is not specified, all 44 rows are returned.

Therefore, the number of rows returned is 4 (Option A).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This SQL previous year question is Q13 of the GATE CSE 2020 paper. Find more GATE CSE PYQs on SQL in Databases, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related SQL PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

SQL in GATE CSE

SQL has 17 GATE CSE PYQs across 14 papers from 2011 to 2025. 6 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2020.

How GATE tests SQL

More from GATE CSE 2020

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2020 · Q13 · MCQ

Consider a relational database containing the following schemas. The primary key of each table is indicated by underlining the constituent fields. 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 number of rows returned by the above SQL query is

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.