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
You can click on above box to edit the code and run again.Select all employee from Ranchi that starts with the letter 'A':
SELECT * FROM employee
WHERE City = 'Ranchi' AND Employee_name LIKE 'A%' ;
Example
SELECT column1, column2, ...You can click on above box to edit the code and run again.
FROM table_name
WHERE condition1 AND condition2 AND condition3...;
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:
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 employeeYou can click on above box to edit the code and run again.
WHERE Country = 'India'
AND City = 'Hazaribagh'
AND Pincode > '825300' ;
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 employeeYou can click on above box to edit the code and run again.
WHERE City = 'Ranchi'
AND (Employee_name LIKE 'A%' OR Employee_name LIKE 'R%' );
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.