GATE CS 2020 Set 1 — Question 23
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.MCQ+1 / -0.33MediumSubqueriesSQLDatabasesAggregate FunctionsGrouping & OrderingSQL Joins
Databases → SQL → Aggregate Functions
Last updated
Question
Consider a relational database containing the following schemas.Catalogue
Suppliers
Parts
The primary key of each table is indicated by underlining the constituent fields.The number of rows returned by the above SQL query is
| sno | pno | cost |
|---|---|---|
| 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 |
| sno | sname | location |
|---|---|---|
| S1 | M/s Royal furniture | Delhi |
| S2 | M/s Balaji furniture | Bangalore |
| S3 | M/s Premium furniture | Chennai |
| pno | pname | part_spec |
|---|---|---|
| P1 | Table | Wood |
| P2 | Chair | Wood |
| P3 | Table | Steel |
| P4 | Almirah | Steel |
| P5 | Almirah | Wood |
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);
Correct answer
(A) 4
Solution
The inner subquery calculates the average cost for part 'P4':Rows for 'P4' in Catalogue are:
(S2, P4, 200)
(S3, P4, 250)
Average cost = .The outer query selects rows from the join of Suppliers and Catalogue where
(S2, P4, 200)
(S3, P4, 250)
Average cost = .The outer query selects rows from the join of Suppliers and Catalogue where
s.sno = c.sno and c.cost > 225.Let's find rows in Catalogue with cost > 225:1.(S2, P5, 250) Matches Supplier S2
2.(S3, P1, 250) Matches Supplier S3
3.(S3, P5, 300) Matches Supplier S3
4.(S3, P4, 250) Matches Supplier S3
The query selects s.sno and s.sname for these entries. Since there is no DISTINCT keyword, all matching rows are returned:1.S2, M/s Balaji furniture
2.S3, M/s Premium furniture
3.S3, M/s Premium furniture
4.S3, M/s Premium furniture
Total number of rows returned is 4.Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on SQL
2026 Set 2 Q15In the context of DBMS, consider the two sets T and S given below. | T | S | |---|---| | I:…2026 Set 2 Q20Consider concurrent execution of two transactions and in a DBMS, both of which access a…2026 Set 1 Q30Let and be the attributes of a relation in a relational schema. Let…2026 Set 1 Q31In the context of relational database normalization, which of the following statements is/are true?2026 Set 2 Q42In the context of schema normalization in relational DBMS, consider a set F of functional…