To display students whose marks have not been entered
Expt. No.31
Page No.62
Marks not entered (IS NULL)
Aim
To display the students whose marks are NULL (not yet entered).
Concepts used
Queries
USE school;SELECT rno, name, marks FROM student WHERE marks IS NULL;SELECT rno, name, marks FROM student WHERE marks = NULL;
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 IS NULL;
+-----+--------+-------+
| rno | name | marks |
+-----+--------+-------+
| 3 | Chetan | NULL |
| 8 | Hina | NULL |
+-----+--------+-------+
2 rows in set
mysql> SELECT rno, name, marks FROM student WHERE marks = NULL;
Empty set
✓ Printed by running this query set, not typed by hand.
Result
IS NULL found Chetan and Hina. The second query, marks = NULL, returned an empty set, which shows why = NULL must never be used.Viva voce: what the examiner may ask
01What does NULL mean?
A missing or unknown value. It is not 0 and not an empty string.
02Why does marks = NULL return nothing?
Any comparison with NULL gives "unknown", which is not true.
03Is NULL the same as 0?
No. 0 is a known value; NULL means the value is not known.
Variations for the lab test
- Count by eye how many students have NULL marks in each class.
- Display students whose date of birth is NULL (there are none).
- Insert a student without marks and check it appears in this query.
! Common mistake Using
= NULL or == NULL: the first returns no rows and the second is a syntax error.