ByteBoard Notes Notes

To display students whose marks have been entered

Informatics Practices XI · Experiment 32 of 36 · SQL

11-IPSQL queries
Expt. No.32
Page No.64

Marks entered (IS NOT NULL)

Aim

To display the students whose marks are not NULL.

Concepts used

Queries

USE school;SELECT rno, name, marks FROM student WHERE marks IS NOT 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 NOT NULL; +-----+--------+-------+ | rno | name | marks | +-----+--------+-------+ | 1 | Aarohi | 78 | | 2 | Bharat | 45 | | 4 | Divya | 91 | | 5 | Eshan | 66 | | 6 | Fatima | 83 | | 7 | Gagan | 38 | | 9 | Ishan | 57 | | 10 | Jaya | 74 | +-----+--------+-------+ 8 rows in set

✓ Printed by running this query set, not typed by hand.

Result

Eight students have their marks entered; only Chetan and Hina were left out.

Viva voce: what the examiner may ask

01How many rows do IS NULL and IS NOT NULL return together?

All the rows of the table (here 2 + 8 = 10).

02How would you show class XII students with marks entered?

WHERE class = 'XII' AND marks IS NOT NULL.

03Can <> NULL be used instead?

No. Like = NULL, it never gives true.

Variations for the lab test

  1. Display girls whose marks are entered.
  2. Display students with marks entered and below 50.
  3. Display the names of students in section A whose marks are entered.
! Common mistake Writing NOT NULL without IS (WHERE marks NOT NULL) is a syntax error.
Back to the 11-IP index