首页 > 技术文章 > sql 判断两条数据库查询语句结果是否有重复

chenxiya 2018-12-26 17:11 原文

select 身份证号 from (select 身份证号 from 表1 where 考试名称= 'aaa'
union all
select 身份证号 from 表2 where 考试名称= 'bbb'
)as A group by 身份证号 HAVING
COUNT (身份证号)>1

注:1、union 表示去掉重复的数据显示 2、union all表示显示所有数据,重复的多条显示 3、从结果中查询不加上 as A时会报错:关键字 'group' 附近有语法错误。

推荐阅读