HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

SQL AND Operator

The WHERE clause can contain one or many AND operators.

The AND operator is used to filter records based on more than one condition, like if you want to return all employee from Ranchi that starts with the letter 'A':

Example

Select all employee from Ranchi that starts with the letter 'A':

SELECT * FROM employee
WHERE City = 'Ranchi' AND Employee_name LIKE 'A%' ;


where and operator
You can click on above box to edit the code and run again.

Example

SELECT   column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3...;
You can click on above box to edit the code and run again.
AND vs OR

The AND operator displays a record if all the conditions are TRUE.

The OR operator displays a record if any of the conditions are TRUE.

Demo Employee table


This employee table is used for examples:

demo employee table

All Conditions Must Be True


The following SQL statement selects all fields from employee where Country is "India" AND City is "Hazaribagh" AND Pincode is higher than 825300:

Example

               SELECT  *  FROM  employee 
WHERE Country = 'India'
AND City = 'Hazaribagh'
AND Pincode > '825300' ;


and_all true condition
You can click on above box to edit the code and run again.

Combining AND and OR


The following SQL statement selects all employee from Ranchi that starts with a "A" or an "R"
Make sure you use parenthesis to get the correct result.

Example

 SELECT  *  FROM  employee 
WHERE City = 'Ranchi'
AND (Employee_name LIKE 'A%' OR Employee_name LIKE 'R%' );

combine and_or

Without parenthesis, the select statement will return all employee from Ranchi that starts with a "A", plus all customers that starts with an "R", regardless of the city value.
You can click on above box to edit the code and run again.