ByteBoard Notes Notes

To display students of class XI and section A

Informatics Practices XI · Experiment 27 of 36 · SQL

11-IPSQL queries
Expt. No.27
Page No.54

Class XI and section A (AND)

Aim

To display the names of students who are in class XI and section A.

Concepts used

Queries

USE school;SELECT rno, name, class, section FROM student WHERE class = 'XI' AND section = 'A';

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, class, section FROM student WHERE class = 'XI' AND section = 'A'; +-----+--------+-------+---------+ | rno | name | class | section | +-----+--------+-------+---------+ | 1 | Aarohi | XI | A | | 2 | Bharat | XI | A | | 9 | Ishan | XI | A | +-----+--------+-------+---------+ 3 rows in set

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

Result

Three students are in class XI section A: Aarohi, Bharat and Ishan. AND kept only the rows where both conditions were true.

Viva voce: what the examiner may ask

01When is A AND B true?

Only when both A and B are true.

02Why is 'XI' written in quotes?

The class column holds text (VARCHAR).

03Is the comparison 'xi' = 'XI' true in MySQL?

Yes. MySQL compares text without regard to case by default.

Variations for the lab test

  1. Display girls of class XII.
  2. Display boys of section B with marks above 40.
  3. Display class XI students born in 2009.
! Common mistake Writing class = 'XI' AND 'A' doesn't compare section at all; the column must be named in each condition.
Back to the 11-IP index