What is Filter data with predicates
The simplest SELECT statements with only SELECT and FROM clauses will evaluate every row in a table. By using a WHERE clause, you define conditions that determine which rows will be processed and potentially reduce result set.
The structure of the WHERE clause
The WHERE clause is made up of one or more search conditions, each of which must evaluate to TRUE, FALSE, or ‘unknown’ for each row of the table. Rows will only be returned when the WHERE clause evaluates as TRUE. The individual conditions act as filters on the data, and are referred to as ‘predicates’. Each predicate includes a condition that is being tested, usually using the basic comparison operators:
- = (equals)
- <> (not equals)
- > (greater than)
- >= (greater than or equal to)
- < (less than)
- <= (less than or equal to)
For example, the following query returns all products with a ProductCategoryID value of 2:
SQLCopy
SELECT ProductCategoryID AS Category, ProductName
FROM Production.Product
WHERE ProductCategoryID = 2;
Similarly, the following query returns all products with a ListPrice less than 10.00:
SQLCopy
SELECT ProductCategoryID AS Category, ProductName
FROM Production.Product
WHERE ListPrice < 10.00;