SQL And – Or

SQL And – Or

AND returns the records if both conditions are true.
OR returns the records if at least one of the conditions is true.

And – Or syntax

SELECT * FROM table_name WHERE condition AND condition;

SELECT * FROM table_name WHERE condition OR condition;

SELECT * FROM table_name WHERE condition AND condition OR condition;

And – Or example

Coder books table

IDTitlePriceDescription
1Learn SQL20Learn SQL language
2Learn MySQL22Learn MySQL language
3HTML book17Learn HTML
4Learn PHP20Introduction to PHP
5Learn PHP20PHP course
SELECT * FROM coder_books WHERE price = 20 and id=4;

Result

IDTitlePriceDescription
4Learn PHP20Introduction to PHP
SELECT * FROM coder_books WHERE price = 22 or id=3;

Result

IDTitlePriceDescription
2Learn MySQL22Learn MySQL language
3HTML book17Learn HTML