select *
from tab1
join tab2 on tab1.[身份证号]=tab2.[身份证号]

解决方案 »

  1.   

    不是很明白你的意思:
    你试试
    select a.*,b.身份证号 from TAB1 a,TAB2 b where a.姓名=b.姓名 and b.性别=a.性别
    and a.身份证号<>b.身份证号
    应该可以查处添错了身份正号的。
      

  2.   

    select * from A.姓名,A.身份证号,B.姓名,B.身份证号 from TAB1 A,TAB2 B where A.姓名+A.身份证号=B.姓名,B.身份证号
      

  3.   


    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
      

  4.   

    /*
    分别从一个表查询是否存在另外一个表,名字和身份证号码相等的,没有匹配的就是名字或者身份证填错,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.身份证号)
      

  5.   

    select * from tb1 where 身份证号 IN (SELECT 身份证号 FORM TB2)
      

  6.   

    不好意思,我少加过来了
    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
      

  7.   

    ---可以查到名字相同,身份证不同的记录,我测试过的~
    --建立测试环境:
    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
      

  8.   

    zhxudong(zhxudong) 你好,你的方法我已经测试,不错。但只显示TAB2的类同记录,如何做到两表的类同记录一起显示出来呢?如:查询出来的记录左边是TAB1的记录右边是TAB2的类同记录,记核对的人一目了然,知道是哪里录错了。请再帮我想想办法,谢谢!
      

  9.   

    请自行参照:http://community.csdn.net/Expert/topic/4180/4180724.xml?temp=.2797205
    http://community.csdn.net/Expert/topic/4172/4172081.xml?temp=8.984011E-02