Share via


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 starts with the number 1 and the store name begins with Bicycle:

SELECT CustomerID, Name 
FROM AdventureWorks.Sales.Store
WHERE CustomerID 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 116 rows whose customer IDs start with 1 or whose store name begins with Bicycle:

SELECT CustomerID, Name 
FROM AdventureWorks.Sales.Store
WHERE CustomerID LIKE '1%' OR Name LIKE N'Bicycle%'

See Also

Other Resources

WHERE (Transact-SQL)
Operators (Transact-SQL)

Help and Information

Getting SQL Server 2005 Assistance