• Learning MySQL By Example
  • Introduction
  • 1. How to Retrieve Data From a Single Table
  • 2. How to Retrieve Data from Multiple Tables
  • 3. Using Functions
  • 4. How to Insert, Update, Delete Data in Tables
  • 5. Summary Queries and Aggregate Functions
  • 6. Working With Subqueries
  • 7. SQL Views
  • 8. SQL Indexes
  • Glossary
  • Index
  • Download
  • Translations
  • 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

    This content is provided to you freely by EdTech Books.

    Access it online or download it at https://edtechbooks.org/learning_mysql/and_or_not_logical_o.