我有两个表中的一个说Employee
与列作为需要联盟样的行为,而不使用查询/结果集的联盟
EmpId Name Class Region
1 rr x t
2 tr v g
另一个表ConfidentalEmployee
与列作为
EmpId(foreign key) Name
1 rr
现在必须写查询与员工表中的所有字段相关,但这些员工标识在ConfidentalEmployee表中,此类员工的详细信息(Class, Region
)应为CAN'T DISCLOSE
,如下所示:
EmpId Name Class Region
1 rr CAN'T DISCLOSE CAN'T DISCLOSE
2 tr v g
我可以使用基于EMPIds的连接使用两个查询并在结果集上执行联合。我的查询如下:
select e.EmpId, e.Name,e.Class,e.Region from Employee e inner join ConfidentalEmployee ce on e.EmpId <> ce.EmpId
UNION
select e.EmpId, e.Name,'CAN'T DISCLOSE' as Class, 'CAN'T DISCLOSE' as Region from Employee e inner join ConfidentalEmployee ce on e.EmpId = ce.EmpId
但我想知道如果它可能与一个单一的查询没有联合操作?
尼斯,我的想法也是如此。 – wiesion
你不需要雇员出席两个表。 –
@LeonardoHerrera。 。 。这表明“机密员工”需要在两个表中,而不是全部员工。 –