sqloperator-precedenceset-operations

Do 'set operations' have an prescribed order of execution, or do they execute in order of evaluation?


Do set operations have a prescribed order of execution (e.g. first UNION, then MINUS, then INTERSECT), or do they execute in the order of which they are scripted and evaluated?

For example, let's say I want to have a starting cohort of customer_ids, then remove some, and then add some back in. Will the set operators execute here as Qry 1 minus Qry 2 union Qry 3?

select cust_id from tbl A
MINUS
select cust_id  from tbl B where field = 'abc'
UNION
select cust_id from tbl A where field = 'xyz'

Solution

  • All set operators have equal precedence. The documentation says

    If a SQL statement contains multiple set operators, then Oracle Database evaluates them from the left to right unless parentheses explicitly specify another order.