oracle之union用法实例

来源:互联网 发布:js点击按钮弹出对话框 编辑:程序博客网 时间:2024/06/04 18:15

govsdm_project :A表
govsdm_projectitem :B表

已知A表和B表中都有部门id(dept_id),现要查询A表和B表记录所涉及的部门总数(不重复)。

union 和 union all都要求两个sql查询列要相同;
union:联合查询出并集(会去除重复记录);
union all:联合查询出并集,包含重复记录;

select count(1) from        (        select dept_id from govsdm_project a where a.is_use='0'            union        select dept_id from govsdm_projectitem b where b.is_use='0'        )
原创粉丝点击