GATE / CS ARCHIVE

GATE CSE 2015 SET 1 / QUESTION 61

GATE CSE 2015 Set 1 Q61

Database Management Systems · SQL & Queries · Full GATE CSE 2015 Set 1 paper

GATE 2015 Set 1, Q61 2 marks · NAT
Report issue

SQL & Queries

Question 61, GATE 2015: Student(Roll_No,Student_Name) rows: (1,Raj),(2,Rohit),(3,Raj). Performance(Roll_No,Course,Marks): (1,Math,80),(1,English,70),(2,Math,75),(3,English,80),(2,Physics,65),(3,Math,80). SQL: SELECT S.Student_Name,sum(P.Marks) FROM Student S,Performance P WHERE S.Roll_No=P.Roll_No GROUP BY S.Student_Name. How many output rows?
Tap to enlarge
Answer & solution

Official answer: 2

The equality join associates each course result with the appropriate student record, producing six joined rows. GROUP BY uses the name column, not the unique roll number, so the two Raj students become one aggregate group. The result contains (Raj,310) and (Rohit,140). Counting students gives three and counting course records gives six, but neither is the number of distinct grouping keys.

Solution: The join matches each performance row to its student by Roll_No, but grouping is by Student_Name alone. Roll numbers 1 and 3 both have name Raj and collapse into one group with total 80+70+80+80=310. Rohit forms the other group with 75+65=140. Hence2 result rows.

Original paper, page 23 · Answer key