SALES: 1-800-867-1380
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
15 out of 26 rated this helpful - Rate this topic

WHERE (Transact-SQL)

Specifies the search condition for the rows returned by the query.

Topic link icon Transact-SQL Syntax Conventions

[ WHERE <search_condition> ]
< search_condition >

Defines the condition to be met for the rows to be returned. There is no limit to the number of predicates that can be included in a search condition. For more information about search conditions and predicates, see Search Condition (Transact-SQL).

The following examples show how to use some common search conditions in the WHERE clause.

A. Finding a row by using a simple equality

USE AdventureWorks2012
GO
SELECT ProductID, Name
FROM Production.Product
WHERE Name = 'Blade' ;
GO

B. Finding rows that contain a value as a part of a string

SELECT ProductID, Name, Color
FROM Production.Product
WHERE Name LIKE ('%Frame%');
GO

C. Finding rows by using a comparison operator

SELECT ProductID, Name
FROM Production.Product
WHERE ProductID <= 12 ;
GO

D. Finding rows that meet any of three conditions

SELECT ProductID, Name
FROM Production.Product
WHERE ProductID = 2
OR ProductID = 4 
OR Name = 'Spokes' ;
GO

E. Finding rows that must meet several conditions

SELECT ProductID, Name, Color
FROM Production.Product
WHERE Name LIKE ('%Frame%')
AND Name LIKE ('HL%')
AND Color = 'Red' ;
GO

F. Finding rows that are in a list of values

SELECT ProductID, Name, Color
FROM Production.Product
WHERE Name IN ('Blade', 'Crown Race', 'Spokes');
GO

G. Finding rows that have a value between two values

SELECT ProductID, Name, Color
FROM Production.Product
WHERE ProductID BETWEEN 725 AND 734;
GO
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.