oracle之union用法实例

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'
        )

你可能感兴趣的:(oracle)