O'Reilly logo

Practical SQL Handbook, The: Using SQL Variants, Fourth Edition by Sandra L. Emerson, Marcy Darnovsky, Judith S. Bowman

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

Connecting Conditions with Logical Operators

Use the logical operators AND, OR, and NOT when you're dealing with more than one condition in a WHERE clause. The logical operators are also called Boolean operators.

AND

AND joins two or more conditions and returns results only when all of the conditions are true. For example, the following query will find only the rows in which the author's last name is Ringer and the author's first name is Anne. It will not find the row for Albert Ringer.

SQL
select au_id, au_lname, au_fname
from authors
where au_lname = 'Ringer'
  and au_fname = 'Anne'

au_id       au_lname                            au_fname
=========== =================================== ========
899-46-2035 Ringer                              Anne
[1 row]

The next example finds business books with a price ...

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