在查询where子句中使用复杂的情况

时间:2019-05-10 13:54:02

标签: sql oracle

Table1
________
ID   Name
_______________
1   First
2   Second

我需要一个查询,该查询将返回Table2中Field1 ='Test'的记录不存在的First 并在表1中存在ID = 1且其中Field1 ='Test'

时返回Second

1 个答案:

答案 0 :(得分:0)

这浮现在脑海:

select (case when exists (select 1 from table2 t2 where t2.field1 = 'Test')
             then 'Second' else 'First'
        end)
from dual;

但是,它不使用table1