O'Reilly logo

Microsoft® SQL Server® 2008 Step by Step by Mike Hotek

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

Filtering Data

The basic SELECT, FROM, and ORDER BY clauses are only marginally useful in building applications. Very few applications will have a requirement to return all of the data in a table, so the WHERE clause is used to limit the results returned. The filtering criteria applied to a query are known as a search argument (SARG).

The following queries are examples of a basic WHERE clause that will return a single row from the Person.Address table.

SELECT * FROM Person.Address WHERE AddressID = 102
SELECT * FROM Person.Address WHERE AddressID = 2

In addition to an equality, you can also test for >, <, >=, <=, and <>. An inequality can be written as either <> or !=. The following queries provide additional examples of a simple WHERE clause.

SELECT ...

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