O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

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

Identifying OR Clauses

The next statements the Query Optimizer looks for in the query are OR clauses. OR clauses are SARGable expressions combined with an OR condition rather than an AND condition and are treated differently than standard SARGs. The format of an OR clause is with all columns involved in the OR belonging to the same table.

SARG or SARG [or ...]

This IN statement

column in ( constant1, constant2, ...)

is also treated as an OR clause, becoming this:

column = constant1 or column = constant2 or ...

Some examples of OR clauses are as follows:

where LastName = 'Smith'  or FirstName = 'Fred'where (Name like '%bearing%' and ListPrice > $25) or ProductSubcategoryID ...

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