Search code examples
sqloracle12csql-in

Two subselect into "IN" (oracle, sql)


How can I use into "IN" two subselect?

I have now:

select colA, colB from table1 where colC in
                 (select T1 from tableT1 where colx = 'Y')
                 and ColD = 'Y';

I need too also that colC will be into second subselect:

select colA, colB from table1 where colC in
                 ((select T1 from tableT1 where colx = 'Y')
                  or
                 (select T2 from tableT2 where colx = 'Y'))
                 and ColD = 'Y';

It's possible to do that? or maybe some union?


Solution

  • You could use a union:

    where colC in
    (
        select T1 from tableT1 where colx = 'Y'
        union
        select T2 from tableT2 where colx = 'Y'
    )
    and ColD = 'Y'