< Sql Tutorial

Sql AND & OR Clause

← Previous Next →


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


SQL AND Operator

The AND operator displays a record if both the first condition AND the second condition are true.

Syntax for SQL AND operator:

SELECT columns  FROM tables  WHERE condition 1  AND condition 2;  

Example

SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin';

SQL OR Operator

The OR operator displays a record if either the first condition OR the second condition is true.

Syntax for SQL OR operator:

SELECT columns  FROM tables  WHERE condition 1  OR condition 2;  

Example

SELECT * FROM Customers WHERE City='Berlin' OR City='München';

Combining AND & OR

You can also combine AND and OR (use parenthesis to form complex expressions). The following SQL statement selects all customers from the country "Germany" AND the city must be equal to "Berlin" OR "München", in the "Customers" table:

Example

SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='München');
← Previous Next →