1.8

AND, OR, NOT Logical Operators

AND, OR, NOT Logical Operators

  • Logical operators are used in the WHERE clause
  • You may use multiple logical operators in a WHERE clause to create a Compound condition. The order of evaluation when multiple operators are used is shown in the table above.

Table 6. Logical Operators

Operator

Description

Order of Evaluation

NOT

( a NOT b ) – a must be present but b must NOT be present to be included

1

AND

( a AND b ) –If  both a and b are present, item is included

2

OR

( a OR b ) – If either a OR b is present item is included

3


Example:

USE world;
SELECT name, population
FROM country
WHERE region = 'caribbean'
AND population > 100000
ORDER BY population ASC;

Results:

logical_operator.png

CC BY-NC-ND International 4.0

CC BY-NC-ND International 4.0: This work is released under a CC BY-NC-ND International 4.0 license, which means that you are free to do with it as you please as long as you (1) properly attribute it, (2) do not use it for commercial gain, and (3) do not create derivative works.

End-of-Chapter Survey

: How would you rate the overall quality of this chapter?
  1. Very Low Quality
  2. Low Quality
  3. Moderate Quality
  4. High Quality
  5. Very High Quality
Comments will be automatically submitted when you navigate away from the page.
Like this? Endorse it!