Did you find this useful?
Socialize it today.


SQL AND/OR Operators

Monday, November 14, 2011

tags SQL

The AND & OR operators are used to filter records based on more than one condition. These operators are very simple to use. The AND operator displays a record if both conditions are TRUE while the OR operator displays a record if either of the conditions are true.

Syntax

SELECT column_name(s)
FROM table_name
where columnName1='some value' AND
columnName2='some value'

or


SELECT column_name(s)
FROM table_name
where columnName1='some value' OR
columnName2='some value'


or you can also combine AND and OR to form complex expressions.


SELECT column_name(s)
FROM table_name
where columnName1='some value' AND
(columnName2='some value' OR columnName3='some value')

Examples

SELECT * FROM Customers
where firstName='John' AND lastName='Smith'

SELECT * FROM Customers
where firstName='John' OR firstName='Jane'

SELECT * FROM Customers
where firstName='John' AND (firstName='Jane' OR firstName='Jill')

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Head First SQL: Your Brain on SQL A Learners Guide SQL Cookbook