将记录与第一个表中的一个附加值匹配

时间:2013-12-09 11:31:36

标签: sql oracle

我有两个表Tab1,Tab2有一列“EmpID”

我的第一个表有值A B C D E第二个表值是A B C。

现在我想要来自两个表的所有公共记录(值A B C)和表1中的一个附加值(值E)。有没有办法在SQL中执行此操作。

感谢 santhosha

1 个答案:

答案 0 :(得分:1)

如果我理解正确,你想要的是如下:

-- giving you all values where empId is equal for Tab1 and Tab2
select t1.empId
from tab1 t1, tab2 t2
where t1.empId = t2.empId

-- union with your value for 'E'
union all
select t1.empid from tab1 t1 where t1.empid = 'E';