- AND operator display only those records where all the given conditions are true.
- OR operator displays only those records where at least one or more conditions are true.
- NOT operator display records where a condition is not true.
To understand these operators, we will use the given table as an example.
id | product_name | price | qty | total |
1 | Pen | 50 | 1 | 50 |
2 | Java Book | 900 | 2 | 1800 |
3 | Mobile | 22000 | 1 | 22000 |
4 | Laptop | 45000 | 2 | 90000 |
AND operator
Fetch all those records which have a price greater than 1000 and qty less than 2.
SELECT * FROM products WHERE price > 1000 AND qty < 2;
id | product_name | price | qty | total |
3 | Mobile | 22000 | 1 | 22000 |
OR Operator
Fetch all those records which have a qty greater than 1 or the total is less than 1000.
SELECT * FROM products WHERE qty > 1 OR total < 1000;
id | product_name | price | qty | total |
1 | Pen | 50 | 1 | 50 |
2 | Java Book | 900 | 2 | 1800 |
4 | Laptop | 45000 | 2 | 90000 |
NOT Operator
Fetch all those records which does not have product_name "Pen"
SELECT * FROM products WHERE NOT product_name="Pen"
id | product_name | price | qty | total |
2 | Java Book | 900 | 2 | 1800 |
3 | Mobile | 22000 | 1 | 22000 |
4 | Laptop | 45000 | 2 | 90000 |