SQL Operator Precedence

Logical Operator has Precedence and here is the ranking:

  • Operator precedence describes the order in which operations are performed when an expression is evaluated.
  • Operations with a higher precedence are performed before those with a lower precedence.
  • Parentheses has the highest precedence and OR has the lowest.
Example:
MySQL, Oracle, SQL server, PostgreSQL:
select ISBN_no "ISBN",
       item_qty*PRICE "Order Sum" 
  from order_books
  where Isbn_no like '%8'
  OR Isbn_no like '0%'
  AND item_qty*PRICE < 100
This will give you:
Find Isbn number and order total for all orders where Isbn_no ends with the letter of 8 or where Isbn number starts with the letter 8 and has an order amount less than $ 100.
The result should be:
ISBN Order Sum
0201703092 78
0764557599 42
0672325764 49
0764557599 84
0764579088 140
0471777781 64
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.