To display students who are in section B or scored above 80
Expt. No.28
Page No.56
Section B or marks above 80 (OR)
Aim
To display students who are in section B or who scored more than 80.
Concepts used
Queries
USE school;SELECT rno, name, section, marks FROM student WHERE section = 'B' OR marks > 80;
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, section, marks FROM student WHERE section = 'B' OR marks > 80;
+-----+--------+---------+-------+
| rno | name | section | marks |
+-----+--------+---------+-------+
| 3 | Chetan | B | NULL |
| 4 | Divya | B | 91 |
| 6 | Fatima | A | 83 |
| 7 | Gagan | B | 38 |
| 8 | Hina | B | NULL |
+-----+--------+---------+-------+
5 rows in set
✓ Printed by running this query set, not typed by hand.
Result
Five students were displayed: the four in section B (whatever their marks, even NULL) and Fatima of section A, who scored 83.
Viva voce: what the examiner may ask
01When is A OR B true?
When at least one of A and B is true.
02Why does Chetan appear although his marks are NULL?
He is in section B, and one true condition is enough for OR.
03Which has higher precedence, AND or OR?
AND. Use brackets to make mixed conditions clear.
Variations for the lab test
- Display students of class XI or with marks below 40.
- Display students who are girls or in section A.
- Combine AND and OR with brackets: (section 'A' or 'B') and class 'XII'.
! Common mistake Mixing AND and OR without brackets can change the meaning, because AND is evaluated first.