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

IDNAMEPRICE
1Learn Python45
2MySQL Tutorial32
3PHP examples24
4Learn SQL32
SELECT * FROM books WHERE price=32 AND id=2;

Output

IDNAMEPRICE
2MySQL Tutorial32
SELECT * FROM books WHERE price=24 OR id=4;

Output

IDNAMEPRICE
3PHP examples24
4Learn SQL32