Skip to content
GATEiit

GATE CSE 2019 Q61: Rows returned by GROUP BY on a cross product without join condition

Syllabus topic: Relational model: relational algebra, tuple calculus and SQL

Question

A relational database contains two tables Student and Performance as shown below:

Student
Roll_no.Student_name
1Amit
2Priya
3Vinit
4Rohan
5Smita
Performance
Roll_no.Subject_codeMarks
1A86
1B95
1C90
2A89
2C92
3C80
SELECT S.Student_name, sum(P.Marks)
FROM Student S, Performance P
WHERE P.Marks > 84
GROUP BY S.Student_name;

The primary key of the Student table is Roll_no. For the Performance table, the columns Roll_no. and Subject_code together form the primary key. Consider the SQL query given above.

The number of rows returned by the above SQL query is ________.

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 5 (official GATE 2019 final answer key)

Concept used: Listing two tables in FROM without a join condition forms their Cartesian product; GROUP BY then returns one row per distinct grouping value that survives the WHERE filter.

Concept notes

Loading notes…

First step: Notice there is no condition linking S and P, so every student is paired with every Performance row having Marks > 84; then count the distinct student names that remain.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Relational model: relational algebra, tuple calculus and SQL

Every PYQ on this topic →

Share this question

WhatsAppDownload image

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