O'Reilly logo

Microsoft SQL Server 2012 Bible by Aaron Nelson, Jose Chinchilla, Patrick LeBlanc, Jorge Segarra, Adam Jorgensen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

WHERE Conditions

The WHERE conditions filter the output of the FROM clause and restrict the returned rows in the result set. The conditions can refer to the data within the tables, expressions, built-in SQL Server scalar functions, other queries, or user-defined functions. The WHERE conditions can also use several possible comparison operators and wildcards, as listed in Table 6.1. In addition, you can combine multiple WHERE conditions using Boolean AND, OR, and NOT operators.

Table 6.1 Standard Comparison Operators

Description Operator Example
Equals = Quantity = 12
Greater than > Quantity > 12
Greater than or equal to >= Quantity >= 12
Less than < Quantity < 12
Less than or equal to <= Quantity<= 12
Not equal to <> , != Quantity <> 12 , Quantity != 12
Not less than !< Quantity !< 12
Not greater than !> Quantity !> 12
Best Practice
To improve the performance of a client/server database, let the database engine do the work of restricting the rows returned, rather than make the client application wade through unnecessary data.
Caution
The comparison operators that include an exclamation point are not ANSI standard SQL. <> is portable; != is not.

referenceaero In addition to the standard comparison operators, which are no doubt familiar, SQL provides four special comparison operators: BETWEEN, IN, LIKE, and IS. The first three are explained in this section. Testing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required