Call (800) 766-1884 for Oracle support & training
Free Oracle Tips

Oracle Consulting Support
Oracle Upgrades
Use New Oracle Features
Oracle Replication Support
Oracle Training
Remote Oracle DBA
System Documentation
Oracle Tips
Oracle Performance

Free Oracle Tips



BC Oracle tuning

Oracle training

Oracle support

Remote Oracle



  Oracle Tips by Burleson

SQL Logical Operators

A SQL query can only have one WHERE clause; however, that clause can contain multiple comparisons.  Each comparison returns a TRUE, FALSE or NULL.  You evaluate these TRUE/FALSE results using AND and OR to end up with the single TRUE or FALSE for the entire WHERE clause.  The AND operator (called conjunction) returns TRUE if both comparisons are TRUE and returns FALSE if either comparison is FALSE. 

WHERE salary < 100000    -- TRUE
AND  dept = ‘SALES’      -- TRUE

Since both comparisons are TRUE, the WHERE clause is TRUE.  The logical OR operator (called a disjunction) returns TRUE if either comparison is TRUE , otherwise returns FALSE. 

WHERE salary < 100000    -- TRUE
OR  dept = ‘SALES’       -- FALSE

The WHERE clause returns TRUE. 

Order of Precedence in SQL

It is important to understand how the database evaluates multiple comparisons in the WHERE clause.  All the AND comparisons (evaluated from Left to Right) are evaluated before the OR comparisons (evaluated from Left to Right).  For example:

   dept = ‘FINANCE’
   dept = ‘SALES’
   salary < 100000;

As you read this query, it appears that you collect all the employees from the finance and sales department and then check that the salary is less than 1000000.  In this case, you would be wrong!  The database will evaluate the AND before the OR.  What this query actually does is list  employees in SALES with salary < 100000, and all the employees in the FINANCE department.

The above book excerpt is from:

Easy Oracle SQL

Get Started Fast writing SQL Reports with SQL*Plus

ISBN 0-9727513-7-8

Col. John Garmany


Oracle performance tuning software 

Oracle performance tuning book


Oracle performance Tuning 10g reference poster
Oracle training in Linux commands
Oracle training Excel
Oracle training & performance tuning books



Copyright © 1996 -  2014 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.