7. Boolean Logic

Keywords Introduced

AND  •  OR  •  NOT  •  BETWEEN  •  IN  •  IS NULL

We introduced the concept of selection criteria in the previous chapter, but only in its simplest form. We’ll now expand on that concept to greatly enhance our ability to specify the rows returned from a SELECT. This is where the pure logic of SQL comes into play. In this chapter, we’ll introduce a number of operators that will allow you to create complex logical expressions.

Given these new capabilities, if a user comes to you and requests a list of all female customers who live in zip codes 60601 through 62999 but excluding anyone under the age of 30 or who doesn’t have an email address, that will be something you can provide.

Complex Logical Conditions ...

Get The Language of SQL, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.