Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> REPOST: Re: UNION & MINUS - strange work together at different situation
y1799_at_yahoo.com (Mike) wrote in message news:<93f42f92.0201241647.6f7d89fc_at_posting.google.com>...
> Hi,
>
> I have two tables: A and B, they both have the same fields. Table A
> contains some records. Table B has the same records and some
> additional records.
>
> If I use such code:
>
> select * from A
> minus
> select * from B
> union
> select * from B
> minus
> select * from A
>
> I get correct result - some string (difference bitween B and A)
>
> But if I use such code
>
> select * from B
> minus
> select * from A
> union
> select * from A
> minus
> select * from B
>
> I get no records as a result. What can be a problem here? Why if last
> part return null string UNION does not work ?
>
> Thanks
> Mike
This is because all set operators have equal precedence, they are evaluated from the left to right if there are no parentheses. In your case, B is a superset of A, so
'select * from A
minus
select * from B
union
select * from B
minus
select * from A'
is the same as
'select * from B minus select * from A',
which gives you what you expected. However
'select * from B
minus
select * from A
union
select * from A
minus
select * from B'
is actually the same as
'select * from B minus select * from B'
which gives nothing. You need to use parentheses.
Regards,
Mike
This message was cancelled from within The Unacanceller's glorious new software, Lotus 1-2-3 For Rogue Cancellers. Received on Fri Jan 25 2002 - 10:51:55 CST
![]() |
![]() |