如果我有2个表,则说TABLE_1
EMP_ID EMP_NAME EMP_COUNTRY
100 John Russia
101 Mitchell UK
102 Sarah Japan
TABLE_2
EMP_ID EMP_NAME EMP_COUNTRY
200 Sunil India
201 Clanton Germany
202 XYZ Australia
我想检查[table_1或table_2]中是否存在EMP_ID,如果它存在于其中一个表中,那么基于该设置一些标志,如何检查这个。
答案 0 :(得分:1)
您也可以尝试:
SELECT DECODE((
SELECT SUM(CNT) FROM
(SELECT COUNT(1) CNT FROM TABLE1 WHERE EMP_ID = yr_emp_id
UNION
SELECT COUNT(1) CNT FROM TABLE2 WHERE EMP_ID = yr_emp_id)),
0,'FALSE','TRUE')
FROM DUAL;
答案 1 :(得分:1)
select count(*)
from
(select emp_id from table_1
union
select emp_id from table_2) t
where t.emp_id = <id_value>
答案 2 :(得分:0)
If (Select Count(*) From TABLE_1 Where EMP_ID = @EMP_ID) > 0
Begin
-- set flag
End
Else If (Select Count(*) From TABLE_2 Where EMP_ID = @EMP_ID) > 0
Begin
-- or set flag here
End