Retrieval Using Both AND and OR Operators

Compound conditions can include both AND and OR logical operators.

Example: If you enter the query:

     SELECT  DNAME, DIV, BUDGET
     FROM    DEPARTMENT
     WHERE   DIV = 'CORP'  AND  BUDGET < 12000  OR  DIV = 'PROD' ;
the result displayed will be:

  DNAME                         DIV     BUDGET
  Supplies and Procurement      CORP    10500
  Research and Development      PROD    27500
  Manufacturing                 PROD    32000
  Customer Support and Service  PROD    11000
  Product Marketing and Sales   PROD    25000

When you have a combination of AND and OR operators, the AND operators are evaluated first; then the OR operators are evaluated. Therefore, in the above query, rows from the DEPARTMENT table are retrieved if they satisfy at least one of the folloiwng conditions:

  1. The department is in the Corporate Division with a budget under $12,000.

  2. The department is in the Product Division.

Copyright © Thunderstone Software     Last updated: Nov 7 2017
Copyright © 2017 Thunderstone Software LLC. All rights reserved.