Skip to content
Official PYQ · 2015

GATE CS 2015 Set 1 Q27 — Tuple Calculus and SQL

Explain with AI

Consider the following relation:

Roll_No‾Student_Name1Raj2Rohit3RajStudentRoll_No‾Course‾Marks1Math801English702Math753English802Physics653Math80Performance\overset{\text{Student}}{\begin{array}{|c|c|}\hline\\ \underline{\textbf{Roll\_No}}& \textbf{Student\_Name}\\ \hline 1& \text{Raj} \\ \hline 2& \text{Rohit}\\ \hline 3& \text{Raj} \\ \hline \end{array}} \qquad\overset{\text{Performance}}{\begin{array}{|c|l|r|c|}\hline\\ \underline{\textbf{Roll\_No}}& \underline{\textbf{Course}}& \textbf{Marks} \\ \hline 1& \text{Math}& 80 \\ \hline 1& \text{English}& 70 \\ \hline 2& \text{Math}& 75 \\ \hline 3& \text{English}& 80 \\ \hline 2& \text{Physics}& 65 \\ \hline 3& \text{Math}& 80 \\ \hline \end{array}}

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 numbers of rows that will be returned by the SQL query is_________________.

View worked solution

Answer: 2

To find the number of rows returned by the SQL query, we analyze the join and grouping operations step-by-step:

  1. Join Operation (S.Roll_No = P.Roll_No): This performs an inner join between Student and Performance. The joined tuples are:
    • For Roll_No 1 (Raj): (Raj, Math, 80), (Raj, English, 70)
    • For Roll_No 2 (Rohit): (Rohit, Math, 75), (Rohit, Physics, 65)
    • For Roll_No 3 (Raj): (Raj, English, 80), (Raj, Math, 80)
  2. Group By Operation (GROUP BY S.Student_Name): The query groups the joined tuples by the attribute Student_Name. The distinct values of Student_Name in the joined relation are "Raj" and "Rohit".

Since there are exactly 2 unique values for Student_Name, the GROUP BY clause creates 2 distinct groups:

  • Group 1 ("Raj"): Sum of marks = 80+70+80+80=31080 + 70 + 80 + 80 = 310
  • Group 2 ("Rohit"): Sum of marks = 75+65=14075 + 65 = 140

Thus, the query returns exactly 2 rows.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions