sql >> Base de Datos >  >> RDS >> Oracle

Seleccionar de la tabla si el registro se encuentra en otra tabla

Puedes hacer algo como esto:

-- If value is found in table2, select from table1
select * -- <- use padding if necessary 
  from table1
 where exists (select 1
                 from table2
                where myField = value)

union all

-- If value is not found in table2, select from another_Table
select * -- <- use padding if necessary
  from another_Table
 where not exists (select 1
                     from table2
                    where myField = value)