不是很明白你的意思: 你试试 select a.*,b.身份证号 from TAB1 a,TAB2 b where a.姓名=b.姓名 and b.性别=a.性别 and a.身份证号<>b.身份证号 应该可以查处添错了身份正号的。
select * from A.姓名,A.身份证号,B.姓名,B.身份证号 from TAB1 A,TAB2 B where A.姓名+A.身份证号=B.姓名,B.身份证号
select * from tab2 where 身份证号 in select 身份证号 from tab1 union select * from tab2 where 姓名 in select 姓名 from tab1或者 select distinct * from ( select * from tab2 where 身份证号 in select 身份证号 from tab1 union select * from tab2 where 姓名 in select 姓名 from tab1 ) as result
/* 分别从一个表查询是否存在另外一个表,名字和身份证号码相等的,没有匹配的就是名字或者身份证填错,select出来 */ select * from Tab1 T1 where NOT EXISTS (SELECT 姓名 FROM Tab2 T2 WHERE T1.姓名 = T2.姓名 AND T1.身份证号 = T2.身份证号) UNION select * from Tab2 T2 where NOT EXISTS (SELECT 姓名 FROM Tab1 T1 WHERE T1.姓名 = T2.姓名 AND T1.身份证号 = T2.身份证号)
select * from tb1 where 身份证号 IN (SELECT 身份证号 FORM TB2)
不好意思,我少加过来了 select * from tab2 where 身份证号 in (select 身份证号 from tab1) union select * from tab2 where 姓名 in (select 姓名 from tab1)或者 select distinct * from ( select * from tab2 where 身份证号 in (select 身份证号 from tab1) union select * from tab2 where 姓名 in (select 姓名 from tab1) ) as result
---可以查到名字相同,身份证不同的记录,我测试过的~ --建立测试环境: create table tab1 (name varchar(8),sex varchar(2),sfzh varchar(20))insert tab1 select '张三','男','451521197901151161' union all select '李四','男','450231198008213316' union all select '王五','男','430231198106213321'create table tab2 (name varchar(8),sex varchar(2),sfzh varchar(20))insert tab2 select '张三','男','451521197902151161' union all select '李四','男','450231198005213316' union all select '王五','男','430231198106213321' select a.name ,b.sex,a.sfzh,b.sfzh from tab1 a join tab2 b on a.name=b.name and a.sfzh!=b.sfzh
你试试
select a.*,b.身份证号 from TAB1 a,TAB2 b where a.姓名=b.姓名 and b.性别=a.性别
and a.身份证号<>b.身份证号
应该可以查处添错了身份正号的。
select * from tab2 where 身份证号 in select 身份证号 from tab1
union
select * from tab2 where 姓名 in select 姓名 from tab1或者
select distinct * from (
select * from tab2 where 身份证号 in select 身份证号 from tab1
union
select * from tab2 where 姓名 in select 姓名 from tab1
) as result
分别从一个表查询是否存在另外一个表,名字和身份证号码相等的,没有匹配的就是名字或者身份证填错,select出来
*/
select * from Tab1 T1 where NOT EXISTS
(SELECT 姓名 FROM Tab2 T2 WHERE T1.姓名 = T2.姓名
AND T1.身份证号 = T2.身份证号)
UNION
select * from Tab2 T2 where NOT EXISTS
(SELECT 姓名 FROM Tab1 T1 WHERE T1.姓名 = T2.姓名
AND T1.身份证号 = T2.身份证号)
select * from tab2 where 身份证号 in (select 身份证号 from tab1)
union
select * from tab2 where 姓名 in (select 姓名 from tab1)或者
select distinct * from (
select * from tab2 where 身份证号 in (select 身份证号 from tab1)
union
select * from tab2 where 姓名 in (select 姓名 from tab1)
) as result
--建立测试环境:
create table tab1 (name varchar(8),sex varchar(2),sfzh varchar(20))insert tab1 select '张三','男','451521197901151161'
union all select '李四','男','450231198008213316'
union all select '王五','男','430231198106213321'create table tab2 (name varchar(8),sex varchar(2),sfzh varchar(20))insert tab2 select '张三','男','451521197902151161'
union all select '李四','男','450231198005213316'
union all select '王五','男','430231198106213321'
select a.name ,b.sex,a.sfzh,b.sfzh from tab1 a join tab2 b on a.name=b.name and
a.sfzh!=b.sfzh
http://community.csdn.net/Expert/topic/4172/4172081.xml?temp=8.984011E-02