How to use the logical operators

The syntax of the WHERE clause with logical operators

      WHERE [NOT] search_condition_1 {AND|OR} [NOT] search_condition_2 ...
      

A search condition that uses the AND operator

      WHERE categoryID = 1 AND discountPercent = 30
      

A search condition that uses the OR operator

      WHERE categoryID = 1 OR discountPercent = 30
      

A search condition that uses the NOT operator

        NOT listPrice >= 500
      

The same condition rephrased to eliminate the NOT operator

      WHERE listPrice < 500
      

A compound condition without parentheses

      SELECT productName, listPrice, discountPercent, dateAdded
      FROM products 
      WHERE dateAdded > '2017-07-01' OR listPrice < 500 
      AND discountPercent > 25;
      
without parentheses image

The same compound condition with parentheses

      SELECT productName, listPrice, discountPercent, dateAdded
      FROM products 
      WHERE (dateAdded > '2017-07-01' OR listPrice < 500) 
      AND discountPercent > 25;
      
with parentheses image

Description

Back