Question

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

Student
rollNumnamegendermarks
1NamanM62
2AliyaF70
3AliyaF80
4JamesM82
5SwatiF65

The 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 _______.

Official answer and solution
Official answer
2
From
Official GATE 2023 answer key

Solution

Evaluate the SQL WHERE predicate gender = 'F' AND marks > 65 against each row of table Student.

Evaluating each tuple in the Student table:

  1. (1, Naman, M, 62): gender = 'M'   ⟹  \implies FALSE.
  2. (2, Aliya, F, 70): gender = 'F' (TRUE) and marks = 70 > 65 (TRUE)   ⟹  \implies Selected.
  3. (3, Aliya, F, 80): gender = 'F' (TRUE) and marks = 80 > 65 (TRUE)   ⟹  \implies Selected.
  4. (4, James, M, 82): gender = 'M'   ⟹  \implies FALSE.
  5. (5, Swati, F, 65): gender = 'F' (TRUE) but marks = 65 > 65 is FALSE (strict inequality)   ⟹  \implies NOT selected.

Exactly 2 rows satisfy the WHERE condition.

Final answer

2

Common trap

Including Swati whose marks are exactly 65 (the condition uses strict inequality > 65).

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2023 Computer Science and Information Technology (CS)
Question
61 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.