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

ID Title Price Description
1 Learn SQL 20 Learn SQL language
2 Learn MySQL 22 Learn MySQL language
3 HTML book 17 Learn HTML
4 Learn PHP 20 Introduction to PHP
5 Learn PHP 20 PHP course
SELECT * FROM coder_books WHERE price = 20 and id=4;

Result

ID Title Price Description
4 Learn PHP 20 Introduction to PHP
SELECT * FROM coder_books WHERE price = 22 or id=3;

Result

ID Title Price Description
2 Learn MySQL 22 Learn MySQL language
3 HTML book 17 Learn HTML