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

適用対象: ○SQL Server ○Azure SQL Database ○Azure SQL Data Warehouse ○Parallel Data WarehouseAPPLIES TO: yesSQL Server yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

クエリによって返される行の検索条件を指定します。Specifies the search condition for the rows returned by the query.

トピック リンク アイコン Transact-SQL 構文表記規則Topic link icon Transact-SQL Syntax Conventions

構文Syntax

[ WHERE <search_condition> ]  

引数Arguments

< 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. 検索条件および述語の詳細については、「検索条件 (Transact-SQL)」を参照してください。For more information about search conditions and predicates, see Search Condition (Transact-SQL).

使用例Examples

以下の例は、WHERE 句でいくつかの一般的な検索条件を使用する方法を示しています。The following examples show how to use some common search conditions in the WHERE clause.

A.A. 単純な等式を使用して行を検索するFinding a row by using a simple equality

-- Uses AdventureWorksDW  
  
SELECT EmployeeKey, LastName  
FROM DimEmployee  
WHERE LastName = 'Smith' ;  

B.B. 値を文字列の一部として含む行を検索するFinding rows that contain a value as part of a string

-- Uses AdventureWorksDW  
  
SELECT EmployeeKey, LastName  
FROM DimEmployee  
WHERE LastName LIKE ('%Smi%');  

C.C. 比較演算子を使用して行を検索するFinding rows by using a comparison operator

-- Uses AdventureWorksDW  
  
SELECT EmployeeKey, LastName  
FROM DimEmployee  
WHERE EmployeeKey  <= 500;  

D.D. 3 つの条件のいずれかを満たす行を検索するFinding rows that meet any of three conditions

-- Uses AdventureWorksDW  
  
SELECT EmployeeKey, LastName  
FROM DimEmployee  
WHERE EmployeeKey = 1 OR EmployeeKey = 8 OR EmployeeKey = 12;  

E.E. 複数の条件を満たす行を検索するFinding rows that must meet several conditions

-- Uses AdventureWorksDW  
  
SELECT EmployeeKey, LastName  
FROM DimEmployee  
WHERE EmployeeKey <= 500 AND LastName LIKE '%Smi%' AND FirstName LIKE '%A%';  

F.F. 値のリストに含まれている行を検索するFinding rows that are in a list of values

-- Uses AdventureWorksDW  
  
SELECT EmployeeKey, LastName  
FROM DimEmployee  
WHERE LastName IN ('Smith', 'Godfrey', 'Johnson');  

G.G. 2 つの値の間の値を持つ行を検索するFinding rows that have a value between two values

-- Uses AdventureWorksDW  
  
SELECT EmployeeKey, LastName  
FROM DimEmployee  
WHERE EmployeeKey Between 100 AND 200;  

参照See Also

DELETE (Transact-SQL) DELETE (Transact-SQL)
述語 (Transact-SQL) Predicates (Transact-SQL)
検索条件 (Transact-SQL) Search Condition (Transact-SQL)
SELECT (Transact-SQL) SELECT (Transact-SQL)
UPDATE (Transact-SQL) UPDATE (Transact-SQL)
MERGE (Transact-SQL)MERGE (Transact-SQL)