Page 266 - PYTHON-12
P. 266
For example, to list the details of all the students who have secured more than 80
marks and are male.
mysql> SELECT * FROM student
WHERE Marks > 80 and Gender= ‘M’;
Resultant table: student
Rollno Name Gender Marks DOB Mobile_no Stream
1. Raj Kumar M 93 17-Nov-2000 9586774748 Science
2. Deep Singh M 98 22-Aug-2000 8988886577 Commerce
8. Akshay Dureja M 90 05-May-1997 9560567890 Commerce
3 rows in a set (0.02 sec)
2. OR operator
The OR operator displays a record and returns a true value if either of the conditions
(usually two conditions) specified in the WHERE clause is true.
Condition 1 Condition 2 Result (OR operation)
True True True
True False True
False True True
False False False
As shown in the table, when either condition 1 or condition 2 is true, the result is
true. If both of them are false, then only the result becomes false.
For example, to display the roll number, name and stream of all the students who are
in either Science or Commerce stream.
mysql> SELECT Rollno, Name, Stream FROM student
WHERE Stream= ‘Science’ or Stream= ‘Commerce’;
Resultant table: student
Rollno Name Stream
1. Raj Kumar Science
2. Deep Singh Commerce
3. Ankit Sharma Science
7. Gurpreet Kaur Science
8. Akshay Dureja Commerce
10. Prateek Mittal Science
6 rows in a set (0.02 sec)
NOT operator
3. NOT operator is also termed as a negation operator. Unlike the other two operators,
Computer Science with Python–XII 12.36 The NOT operator displays a record and returns a true value if either of the conditions
this operator takes only one condition and gives the reverse of it as the result. It
returns a false value if the condition holds true and vice versa.
(usually two conditions) specified in the WHERE clause is true.
Result (NOT operation)
Condition 1
True
False
True
False
As shown in the table, when the condition is true, the result is false. If the condition
is false, then the result becomes true.