ByteBoard Notes Notes

Use the select command to get the details of the students with marks more than 80

Informatics Practices XII · Experiment 26 of 38 · SQL

★ CBSE suggested12-IPSQL queries
Expt. No.26
Page No.52

Marks more than 80

Aim

To display the details of students who scored more than 80.

Concepts used

Queries

USE school;SELECT * FROM student WHERE marks > 80;

A marked line continues the line above it. In your file, write it on the same line.

Table used

Table: student
+-----+-------+-------+
| sid | name  | marks |
+-----+-------+-------+
|   1 | Asha  |    82 |
|   2 | Rohan |    67 |
|   3 | Ira   |    88 |
|   4 | Kabir |    91 |
|   5 | Diya  |    74 |
|   6 | Neel  |  NULL |
+-----+-------+-------+

Output

mysql> USE school; Database changed
mysql> SELECT * FROM student WHERE marks > 80; +-----+-------+-------+ | sid | name | marks | +-----+-------+-------+ | 1 | Asha | 82 | | 3 | Ira | 88 | | 4 | Kabir | 91 | +-----+-------+-------+ 3 rows in set

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

Result

Asha (82), Ira (88) and Kabir (91) scored more than 80. Neel's NULL marks are not compared as greater than 80.

Viva voce: what the examiner may ask

01Does > 80 include 80?

No. Use >= 80 to include it.

02Why is Neel not in the result?

His marks are NULL, and comparing NULL with 80 is never true.

03What does * mean?

All the columns.

Variations for the lab test

  1. Display students who scored between 70 and 90.
  2. Display only the names of students above 80.
  3. Display students who scored 80 or less.
! Common mistake Writing WHERE marks > 80% is a syntax error; marks are stored as plain numbers.
Back to the 12-IP index