A relational database contains two tables Student and Performance as shown below:
The primary key of the Student table is Roll_no. For the performance table, the columns Roll_no. and Subject_code together form the primary key. Consider the SQL query given below:
SELECT S.Student_name, sum(P.Marks) FROM Student S, Performance P WHERE P.Marks >84 GROUP BY S.Student_name;
The number of rows returned by the above SQL query is ________
View worked solution
Answer: 5
To find the number of rows returned by the SQL query, let us analyze the query step-by-step:
1. Identify the Join Condition
Notice that the query performs a cross join (Cartesian product) because there is no join condition (such as S.Roll_no = P.Roll_no) specified in the WHERE clause:
FROM Student S, Performance P
2. Apply the Filter Condition
The WHERE clause filters the Performance table for rows where Marks > 84:
- Roll_no 1, Subject A: (True)
- Roll_no 1, Subject B: (True)
- Roll_no 1, Subject C: (True)
- Roll_no 2, Subject A: (True)
- Roll_no 2, Subject C: (True)
- Roll_no 3, Subject C: (False)
There are exactly rows in the Performance table that satisfy this condition.
3. Cartesian Product
The Student table contains unique students:
- Amit
- Priya
- Vinit
- Rohan
- Smita
Since a Cartesian product is performed, each of these students is paired with each of the filtered rows from the Performance table, resulting in intermediate rows.
4. Group By Clause
The query groups the result by S.Student_name:
GROUP BY S.Student_name;
Since all student names in the Student table are distinct, the grouping operation will create exactly groups (one for each student name).
Each group produces exactly one row in the final output containing the student's name and the sum of marks (which will be for each student).
Thus, the number of rows returned by the query is .
Free practice · Your answers on this page are not saved.
