UNION resultset

Analytics
Enthusiast

UNION resultset

Hi,

 

I have below query involving UNION/MINUS clause whose resultset i am unable to understand.

 

Below 2 tables are there

 

CREATE MULTISET TABLE table1
(
   emp_id INTEGER
   ,salary INTEGER
)

INSERT INTO table1 VALUES(1,100)


CREATE MULTISET TABLE table2
(
 emp_id INTEGER
,salary INTEGER
)

 
 INSERT INTO table2 VALUES(1,200)

 

I am trying to find the differences between the 2 tables

 

SELECT * FROM table1
   MINUS
SELECT * FROM table2
    UNION
SELECT * FROM table2
   MINUS
SELECT * FROM table1

 

Above query gives below resultset

    emp_id    salary
    1    200

 

Below query gives

 

SELECT * FROM table1
   MINUS
SELECT * FROM table2
    UNION

(
SELECT * FROM table2
   MINUS
SELECT * FROM table1

)

    emp_id    salary
    1    100
    1    200

Can anyone help me understand what is the difference between the 2 queries ?

 

 

 


Accepted Solutions
Highlighted
Junior Contributor

Re: UNION resultset

See the manuals

The precedence for processing set operators is as follows:
1. INTERSECT
2. UNION and MINUS/EXCEPT
The set operators evaluate from left to right if no parentheses explicitly specify another order.

1 ACCEPTED SOLUTION
2 REPLIES 2
Highlighted
Junior Contributor

Re: UNION resultset

See the manuals

The precedence for processing set operators is as follows:
1. INTERSECT
2. UNION and MINUS/EXCEPT
The set operators evaluate from left to right if no parentheses explicitly specify another order.

Enthusiast

Re: UNION resultset

That answers my queries. Thank you.