select *
from ((select 'FINANCE' as dept, 42 as employees from dual) union
(select 'SALES' as dept, 32 as employees from dual)) departments
where
departments.dept = 'FINANCE'
or
departments.dept = 'SALES'
and
departments.employees < 30;
returns: FINANCE 42
from ((select 'FINANCE' as dept, 42 as employees from dual) union
(select 'SALES' as dept, 32 as employees from dual)) departments
where
departments.dept = 'FINANCE'
or
departments.dept = 'SALES'
and
departments.employees < 30;
returns: FINANCE 42
Clearly, AND takes precedence over OR, as usual.
A AND B OR C => (A AND B) OR C
A OR B AND C => A OR (B AND C)
A OR B AND C => A OR (B AND C)
References
- Stackoverflow - sql logic operator precedence
- http://stackoverflow.com/questions/1241142/sql-logic-operator-precedence-and-and-or
- SQL Logical Operators
- http://www.praetoriate.com/t_garmany_easysql_sql_logical_operators.htm
No comments:
Post a Comment