Question
Consider the following table named Student in a relational database. The primary key of this table is rollNum.
| rollNum | name | gender | marks |
|---|---|---|---|
| 1 | Naman | M | 62 |
| 2 | Aliya | F | 70 |
| 3 | Aliya | F | 80 |
| 4 | James | M | 82 |
| 5 | Swati | F | 65 |
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, Naman, M, 62):gender = 'M'FALSE.(2, Aliya, F, 70):gender = 'F'(TRUE) andmarks = 70 > 65(TRUE) Selected.(3, Aliya, F, 80):gender = 'F'(TRUE) andmarks = 80 > 65(TRUE) Selected.(4, James, M, 82):gender = 'M'FALSE.(5, Swati, F, 65):gender = 'F'(TRUE) butmarks = 65 > 65is FALSE (strict inequality) NOT selected.
Exactly 2 rows satisfy the WHERE condition.
2
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.