①取合集
select id from
(
select id from A
UNION
select id from B
)ti
UNION会自动去重
②取交集
select id from
(
select id from A
UNION ALL
select id from B
)ti group ti.id having count(id)>1
UNION ALL 不会自动去重
或
select id from
(
select id from A
)ti
and id in (select id from B)
欢迎指正~
本文介绍了如何使用SQL进行集合操作,包括取合集与交集的方法。取合集时使用UNION关键字可以自动去除重复记录;而取交集则可以通过UNION ALL结合GROUP BY和HAVING子句实现,或者通过子查询和IN关键字来完成。

被折叠的 条评论
为什么被折叠?



