Joining tables with full outer join and… COALESCE

coalescejoin;oracle

I have a few tables in an Oracle database linked by id – fk_id, if I do:

select RAP.ID_PCT_LUCRU,SES_RAP.AN,
        TIS.CANT as c1,'R12' as modc1,
        TIT.CANT as c2,'D13' as modc2,
        TIMB.CANT as c3,'D8' as modc3,
        TIFC.CANT as c4,
        TIA.CANT as c5
     from ch_trat cht
        full outer join raportor rap on cht.fk_id_raportor = rap.id
        inner join sr ses_rap on ses_rap.id = CHT.FK_ID_SR
        full outer join sortare tis on TIS.FK_TRAT_ID = CHT.ID
        full outer join transfer tit on TIT.FK_TRAT_ID = CHT.ID
        full outer join mec_bio timb on TIMB.FK_TRAT_ID = CHT.ID
        full outer join fiz_chm tifc on TIFC.FK_TRAT_ID = CHT.ID
        full outer join altele tia on TIA.FK_TRAT_ID = CHT.ID

and the result is something like this:

ID_PCT_LUCRU    AN     c1    modc1  c2   modc2  c3   modc3  c4  c5
275382          2013         R12         D13         D8     
280933          2013         R12    222  D13         D8         44
295740          2013         R12         D13         D8    111  73
297089          2013         R12         D13    333  D8         124
281137          2013         R12         D13         D8    222  19
281137          2013         R12    222  D13         D8         123
281137          2013         R12         D13         D8         14
301410          2013   5103  R12         D13    444  D8         880

So I'd want that the result doesn't show me the first row with no value on c1,c2,c3,c4,c5. I know I should use COALESCE but I don't know how to use it in this case.
Many Thanks!

Best Answer

You can make it a subquery:

select * from (...) a
where coalesce(a.c1, coalesce(a.c2, coalesce(a.c3, coalesce(a.c4, coalesce(a.c5, null))))) is not null

You just put your query at the dots.

EDIT:

You just put where coalesce(TIS.CANT, TIT.CANT, TIMB.CANT, TIFC.CANT, TIA.CANT) is not null as a where clause in your query, as Andriy said. :)