simplify_life
simplify_life

Reputation: 405

Oracle Minus query

I have problem with Oracle minus query. If my query is like this

 select col1 from 
(select '1' col1 from dual
union
select '2' col1 from dual )
minus
select col1 from 
(select '1' col1 from dual
 );

Result is as expected 2 . But If I put a Semicolon after Query 1 as below

select col1 from 
(select '1' col1 from dual
union
select '2' col1 from dual );
minus
select col1 from 
(select '1' col1 from dual
 );

Result is 1 .Can anybody explain me why Result is like this. I am using PL/SQL Developer

Upvotes: 0

Views: 855

Answers (1)

Hamidreza
Hamidreza

Reputation: 3128

When you put the semicolon after first select it means that the select is finished, there for you got two separated selects

first select is:

select col1 from 
(select '1' col1 from dual
union
select '2' col1 from dual );

and it returns 1 and 2

the second is:

minus
select col1 from 
(select '1' col1 from dual
);

minus haven't got any meaning in this part but the select can run and it returns 1

there for you just run your query from the second part and see 1 as your result.

Upvotes: 3

Related Questions