| title | WHERE (Transact-SQL) | |||||
|---|---|---|---|---|---|---|
| description | The WHERE clause specifies the search condition for the rows returned by the query. | |||||
| author | VanMSFT | |||||
| ms.author | vanto | |||||
| ms.reviewer | randolphwest | |||||
| ms.date | 10/01/2025 | |||||
| ms.service | sql | |||||
| ms.subservice | t-sql | |||||
| ms.topic | reference | |||||
| ms.custom |
|
|||||
| f1_keywords |
|
|||||
| helpviewer_keywords |
|
|||||
| dev_langs |
|
|||||
| monikerRange | >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric || =fabric-sqldb |
[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]
Specifies the search condition for the rows returned by the query.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
[ WHERE <search_condition> ]
Defines the condition to be met for the rows to be returned. There's 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.
[!INCLUDE article-uses-adventureworks]
The following examples show how to use some common search conditions in the WHERE clause.
-- Uses AdventureWorksDW
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE LastName = 'Smith';-- Uses AdventureWorksDW
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE LastName LIKE '%Smi%';-- Uses AdventureWorksDW
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE EmployeeKey <= 500;-- Uses AdventureWorksDW
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE EmployeeKey = 1
OR EmployeeKey = 8
OR EmployeeKey = 12;-- Uses AdventureWorksDW
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE EmployeeKey <= 500
AND LastName LIKE '%Smi%'
AND FirstName LIKE '%A%';-- Uses AdventureWorksDW
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE LastName IN ('Smith', 'Godfrey', 'Johnson');-- Uses AdventureWorksDW
SELECT EmployeeKey, LastName
FROM DimEmployee
WHERE EmployeeKey BETWEEN 100 AND 200;