A relational database contains two tables Student and Performance as shown…

2019

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 ________.

Attempted by 188 students.

Show answer & explanation

Correct answer: 5

Key idea: the query uses the two tables without a join condition, so rows are formed by the Cartesian product and then filtered by the WHERE clause that refers only to the Performance table.

Step-by-step reasoning:

  • Find all Performance rows satisfying Marks > 84.

  • The qualifying Performance rows are: (Roll_no 1, subject A, 86), (Roll_no 1, subject B, 95), (Roll_no 1, subject C, 90), (Roll_no 2, subject A, 89), (Roll_no 2, subject C, 92).

  • There are 5 Performance rows with Marks > 84.

  • Because the query does not relate Student and Performance by Roll_no, each student will pair with all these qualifying Performance rows (Cartesian product filtered by the WHERE clause).

  • Grouping by student name therefore produces one aggregated row per student present in the Student table.

Since the Student table has 5 students, the query returns 5 rows.

Final answer: 5 rows.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir