GATE CS 2015 · Set-1 · SQL Queries

NAT · 2 marks · Problem DBMS-SQL-0089

Consider the following relations:\[\begin{array}{cc} \textbf{Student} & \textbf{Performance} \\ \begin{array}{|c|c|} \hline \text{Roll\_No} & \text{Student\_Name} \\ \hline 1 & \text{Raj} \\ 2 & \text{Rohit} \\ 3 & \text{Raj} \\ \hline \end{array} & \begin{array}{|c|c|c|} \hline \text{Roll\_No} & \text{Course} & \text{Marks} \\ \hline 1 & \text{Math} & 80 \\ 1 & \text{English} & 70 \\ 2 & \text{Math} & 75 \\ 3 & \text{English} & 80 \\ 2 & \text{Physics} & 65 \\ 3 & \text{Math} & 80 \\ \hline \end{array} \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 number of rows that will be returned by the SQL query is

Numerical answer (NAT).

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solution\[\boxed{\text{GROUP BY Student\_Name: one row per distinct name}}\]Every student has marks, so the join keeps all three students. Grouping is by name, not by roll number, and the names are Raj, Rohit, Raj: two distinct names.Raj gets \(80 + 70 + 80 + 80 = 310\) and Rohit \(75 + 65 = 140\): \(2\) rows.Answer: 2

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com