mardi 31 juillet 2018

union of two query return null when one of query result is empty. how to handle it?

i have a query where i wrap two query by union in another select query for example:

select A,B from (select x,y from firsttable where bla bla bla 
union
select C,D from secondtable where bla bla bla) group by Z;

Now when firstTable or secondtable have empty result because of where condition then it return result as

1st row> NULL | NULL | NULL

2nd row> 1 | 2 | 3 <- this is result of second or first (but one table) when one table where clause have something to return.

note: when both where condition have values to return then no such problem. the problem occre only when one of wrapped query return empty set. when both where query have values then it give desirable result which is only one row because it is grouped




Aucun commentaire:

Enregistrer un commentaire