Consider the following relation:
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:
- Join Operation (
S.Roll_No = P.Roll_No): This performs an inner join betweenStudentandPerformance. 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)
- Group By Operation (
GROUP BY S.Student_Name): The query groups the joined tuples by the attributeStudent_Name. The distinct values ofStudent_Namein 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 =
- Group 2 ("Rohit"): Sum of marks =
Thus, the query returns exactly 2 rows.
Free practice · Your answers on this page are not saved.
