A newer version of this documentation is available.

View Latest

Logical Operators

  • reference
    +

    Logical terms let you combine other expressions using Boolean logic. N1QL provides the following logical operators:

    • AND

    • OR

    • NOT

    In N1QL, logical operators have their usual meaning; however, Boolean propositions can evaluate to NULL or MISSING as well as to TRUE and FALSE. The truth tables for these operators therefore use four-valued logic.

    AND

    condition AND condition
    Syntax diagram

    AND evaluates to TRUE only if both conditions are TRUE.

    Table 1. AND Truth Table
    TRUE FALSE NULL MISSING

    TRUE

    TRUE

    FALSE

    NULL

    MISSING

    FALSE

    FALSE

    FALSE

    FALSE

    FALSE

    NULL

    NULL

    FALSE

    NULL

    MISSING

    MISSING

    MISSING

    FALSE

    MISSING

    MISSING

    OR

    condition OR condition
    Syntax diagram

    OR evaluates to TRUE if one of the conditions is TRUE.

    Table 2. OR Truth Table
    TRUE FALSE NULL MISSING

    TRUE

    TRUE

    TRUE

    TRUE

    TRUE

    FALSE

    TRUE

    FALSE

    NULL

    MISSING

    NULL

    TRUE

    NULL

    NULL

    NULL

    MISSING

    TRUE

    MISSING

    NULL

    MISSING

    NOT

    NOT condition
    Syntax diagram

    NOT evaluates to TRUE if the condition is FALSE, and vice versa.

    Table 3. NOT Truth Table
    NOT

    TRUE

    FALSE

    FALSE

    TRUE

    NULL

    NULL

    MISSING

    MISSING

    For further details, refer to Boolean Logic.