AND OR in MySQL

MySQL AND OR
In MySQL, the AND and OR conditions are also used in combination to filter the results obtained through the SELECT, INSERT, UPDATE, and DELETE statements based on more than one condition.

Syntax:

WHERE condition_1
AND condition_2
..
OR condition_n;

Parameters:

condition_1, condition_2… condition_n: They specify the conditions to be strictly followed for selection.

Example: Items table:

ID NAME QUANTITY
1 Electronics 30
2 Sports 45
3 Fashion 100
4 Grocery 90
5 Toys 50

 

Query:

SELECT *
FROM items
WHERE (id < 4 AND quantity > 50)
OR id > 3;

Output:

ID NAME QUANTITY
3 Fashion 100
4 Grocery 90
5 Toys 50