Export (0) Print
Expand All

Logical Operators

The logical operators are AND, OR, and NOT. AND and OR are used to connect search conditions in WHERE clauses. NOT reverses the result of a search condition.

AND joins two conditions and returns TRUE only when both conditions are true. For example, this query returns only the one row in which the customer ID (BusinessEntityID) starts with the number 1 and the store name begins with Bicycle:

SELECT BusinessEntityID, Name 
FROM AdventureWorks2008R2.Sales.Store
WHERE BusinessEntityID LIKE '1%' AND Name LIKE N'Bicycle%';

OR also connects two conditions, but it returns TRUE when either of the conditions is true. The following query returns the 349 rows whose customer IDs start with 1 or whose store name begins with Bicycle:

SELECT BusinessEntityID, Name 
FROM AdventureWorks2008R2.Sales.Store
WHERE BusinessEntityID LIKE '1%' OR Name LIKE N'Bicycle%';
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft