Skip to content
Official PYQ · 2023

GATE CS 2023 Q51 — Tuple Calculus and SQL

Explain with AI

Consider the following table named Student\text{Student} in a relational database. The primary key of this table is rollNum.\text{rollNum}.

Student\text{Student}
rollNum‾namegendermarks1NamanM622AliyaF703AliyaF804JamesM825SwatiF65\begin{array}{|c|l|c|c|} \hline \underline{\text{rollNum}} & \text{name} & \text{gender} & \text{marks} \\ \hline \hline 1 & \text{Naman} & \mathrm{M} & 62 \\ \hline 2 & \text{Aliya} & \mathrm{F} & 70 \\ \hline 3 & \text{Aliya} & \mathrm{F} & 80 \\ \hline 4 & \text{James} & \mathrm{M} & 82 \\ \hline 5 & \text{Swati} & \mathrm{F} & 65 \\ \hline \end{array}

The SQL\text{SQL} query below is executed on this database.

SELECT *
FROM Student
WHERE gender = 'F' AND
    marks  > 65;

The number of rows returned by the query is ___________.

View worked solution

Answer: 2

To find the number of rows returned by the SQL query, we evaluate the condition in the WHERE clause for each row in the Student table:

Condition: gender=’F’ AND marks>65\text{Condition: } \text{gender} = \text{'F'} \text{ AND } \text{marks} > 65

Let's check each row individually:

  1. rollNum 1 (Naman): gender = 'M' (False). The condition fails.
  2. rollNum 2 (Aliya): gender = 'F' (True) and marks = 70 > 65 (True). The condition is True.
  3. rollNum 3 (Aliya): gender = 'F' (True) and marks = 80 > 65 (True). The condition is True.
  4. rollNum 4 (James): gender = 'M' (False). The condition fails.
  5. rollNum 5 (Swati): gender = 'F' (True) but marks = 65 > 65 is False (since 6565 is not strictly greater than 6565). The condition fails.

The rows with rollNum 2 and 3 satisfy the query condition.

Thus, the number of rows returned by the query is 2.

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

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions