Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problems with query result using UNION

shabbirFeb 24 2016 — edited Feb 24 2016

Hi All

I have a very weird situation, which i cant understand. Please help me out. Below is my problem scenario.

I have 2 queries having a UNION between them

select

COMPANY    DEPARTMENT    NATURAL_ACCOUNT    LOCATION    CONTRACT    INTERCOMPANY    FUTURE1    FUTURE2    ASSIGNMENT_ACTION_ID    DEBIT    CREDIT

from my_tables

where my conditions

and my checks

UNION

select

COMPANY    DEPARTMENT    NATURAL_ACCOUNT    LOCATION    CONTRACT    INTERCOMPANY    FUTURE1    FUTURE2    ASSIGNMENT_ACTION_ID    DEBIT    CREDIT

from my_tables

where my other conditions

and my other checks

Now the upper query returns 3 records while the lower query doesn't return any records (for certain set of parameters). The output in this case using UNION shows only 2 records (omitting the last record). I confirmed this by replacing the second query with the below query

UNION

select

null COMPANY    null DEPARTMENT    null NATURAL_ACCOUNT    null LOCATION   null CONTRACT   null INTERCOMPANY   null FUTURE1   null FUTURE2   null ASSIGNMENT_ACTION_ID   null DEBIT   null CREDIT

from dual

I cant use UNION ALL because its against my interest for the other set of parameters. Please help me out, why last record gets ignored or omitted

Regards

This post has been answered by RakeshD on Feb 24 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 23 2016
Added on Feb 24 2016
7 comments
664 views