假設有表(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 )
結果: