To display Rno, Name and Marks of students scoring more than 50
Expt. No.25
Page No.50
Marks more than 50
Aim
To display the roll number, name and marks of students who scored more than 50.
Concepts used
Queries
USE school;SELECT rno, name, marks FROM student WHERE marks > 50;
A marked line continues the line above it. In your file, write it on the same line.
Table used
Table: student
+-----+-------+---------+--------+--------+------------+-------+ | rno | class | section | gender | name | dob | marks | +-----+-------+---------+--------+--------+------------+-------+ | 1 | XI | A | F | Aarohi | 2009-03-14 | 78 | | 2 | XI | A | M | Bharat | 2008-11-02 | 45 | | 3 | XI | B | M | Chetan | 2009-07-21 | NULL | | 4 | XI | B | F | Divya | 2009-01-30 | 91 | | 5 | XII | A | M | Eshan | 2008-05-17 | 66 | | 6 | XII | A | F | Fatima | 2008-09-09 | 83 | | 7 | XII | B | M | Gagan | 2007-12-25 | 38 | | 8 | XII | B | F | Hina | 2008-02-11 | NULL | | 9 | XI | A | M | Ishan | 2009-10-05 | 57 | | 10 | XII | A | F | Jaya | 2008-06-28 | 74 | +-----+-------+---------+--------+--------+------------+-------+
Output
mysql> USE school;
Database changed
mysql> SELECT rno, name, marks FROM student WHERE marks > 50;
+-----+--------+-------+
| rno | name | marks |
+-----+--------+-------+
| 1 | Aarohi | 78 |
| 4 | Divya | 91 |
| 5 | Eshan | 66 |
| 6 | Fatima | 83 |
| 9 | Ishan | 57 |
| 10 | Jaya | 74 |
+-----+--------+-------+
6 rows in set
✓ Printed by running this query set, not typed by hand.
Result
Six students scored more than 50. Rows with NULL marks were not shown, because NULL > 50 is not true.
Viva voce: what the examiner may ask
01What does the WHERE clause do?
It keeps only the rows for which the condition is true.
02Why are Chetan and Hina missing from the output?
Their marks are NULL; a comparison with NULL is never true.
03Which relational operators can be used in WHERE?
=, <>, !=, <, >, <= and >=.
Variations for the lab test
- Display students who scored 50 or less.
- Display students of class XII who scored more than 50.
- Display students whose marks are not equal to 78.
! Common mistake Writing
marks > '50' with quotes works in MySQL but compares inconsistently in other systems; numbers should be written without quotes.