我有两个SQL查询。
select EmployeeID,FName from [Mydatabase].[dbo].EMPLOYEE_TABLE where EmployeeID not in
(select ManagerID from [Mydatabase].[dbo].ORG_UNIT where OrgUnitID = '5')and OrgUnitID = '5'
这会返回两行。 还有另一个问题..
(select EmployeeID,FName from [Mydatabase].[dbo].EMPLOYEE_TABLE where EmployeeID in
(select ManagerID from [Mydatabase].[dbo].ORG_UNIT where ParentTeamID = '5'))
这会返回一行。
我想结合结果以便最终得到三行..有没有办法做到这一点???
答案 0 :(得分:3)
SELECT EmployeeID, FName
FROM EMPLOYEE_TABLE
WHERE EmployeeID NOT IN
(
SELECT ManagerID
FROM ORG_UNIT
WHERE OrgUnitID = '5'
)
AND OrgUnitID = '5'
UNION ALL
SELECT EmployeeID, FName
FROM EMPLOYEE_TABLE
WHERE EmployeeID IN
(
SELECT ManagerID
FROM ORG_UNIT
WHERE ParentTeamId = '5'
)
如果员工可以匹配这两个条件,请将UNION ALL
替换为UNION
,以便不会再返回一个id
。
答案 1 :(得分:0)
你可以同时执行它们吗?您可以将查询(具有匹配的列)与“UNION ALL”子句组合在一起。