The GATE Grind

GATE 2015 CS – Question 61

Databases · Relational Model: Relational Algebra, Tuple Calculus, SQL · 2 marks · Numerical answer

Consider the following relations:

Student

Roll_NoStudent_Name
1Raj
2Rohit
3Raj

Performance

Roll_NoCourseMarks
1Math80
1English70
2Math75
3English80
2Physics65
3Math80

Consider the following SQL query.

SELECT S.Student_Name, sum(P.Marks)
FROM Student S, Performance P
WHERE S.Roll_No = P.Roll_No
GROUP BY S.Student_Name

The number of rows that will be returned by the SQL query is ________.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 2

Explanation

The query groups the joined rows by student name, not by roll number. The names are Raj, for roll numbers 1 and 3, and Rohit, for roll number 2. That gives two groups, so the query returns 2 rows.