And – Or

SQL AND & OR

AND returns rows from sql table if both conditions are true.
OR returns rows from sql table if at least one of the conditions is true.

Syntax

SELECT * FROM name_of_table WHERE condition AND condition;
SELECT * FROM name_of_table WHERE condition OR condition;
SELECT * FROM name_of_table WHERE condition AND condition OR condition;

Example

Table of books

ID NAME PRICE
1 Learn Python 45
2 MySQL Tutorial 32
3 PHP examples 24
4 Learn SQL 32
SELECT * FROM books WHERE price=32 AND id=2;

Output

ID NAME PRICE
2 MySQL Tutorial 32
SELECT * FROM books WHERE price=24 OR id=4;

Output

ID NAME PRICE
3 PHP examples 24
4 Learn SQL 32