假设有表(UserTB): 1、Union(不允许重复) ? 1 2 3 4 5 6 7 SELECT * FROM dbo.UserTB WHERE deptId IN ( 1, 3 ) UNION SELECT * FROM dbo.UserTB WHERE deptId IN ( 1, 2 ) 结果: 2、Union All(允许重复) ? 1 2 3 4 5 6 7 SELECT * FROM dbo.UserTB WHER
假设有表(UserTB):
1、Union(不允许重复)
?
1
2
3
4
5
6
7
SELECT *
FROM dbo.UserTB
WHERE deptId IN ( 1, 3 )
UNION
SELECT *
FROM dbo.UserTB
WHERE deptId IN ( 1, 2 )
结果:
2、Union All(允许重复)
?
1
2
3
4
5
6
7
SELECT *
FROM dbo.UserTB
WHERE deptId IN ( 1, 3 )
UNION ALL
SELECT *
FROM dbo.UserTB
WHERE deptId IN ( 1, 2 )
结果: