WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL AND & OR Operators

AND & OR Operators are used to filter records based on more than one condition.


SQL AND & OR Operator

If both the first and second conditions are true, the AND operator displays a record.

If only one of the first and second conditions is true, the OR operator displays a record.


Demo database

In this tutorial, we will use the welookups sample database.

Here is the data from the "Websites" table:

+----+--------------+---------------------------+-------+---------+
| id | name         | url                       | alexa | country |
+----+--------------+---------------------------+-------+---------+
| 1  | Google       | https://www.google.cm/| 1     | USA     |
| 2  | Indiatimes          | https://www.Indiatimes.com/|  9   | IN      |
| 3  | zomato      | http://www.zomato.com/| 83    | IN      |
| 4  | indiamart          | http://indiamart.com/   | 33       |  IN      |
| 5  | Facebook     | https://www.facebook.com/| 3     | USA     |
+----+--------------+---------------------------+-------+---------+

AND operator example

The following SQL statement selects all websites from the "Websites" table whose country is "IN" and alexa rank is greater than "50":

Examples

SELECT * FROM Websites WHERE country='IN' AND alexa > 50;

OR operator example

The following SQL statement selects all customers whose country is "USA" or "IN" from the "Websites" table:

Example

SELECT * FROM Websites WHERE country='USA' OR country='IN';