--我测试了,语句是对的,也没出现你说的情况,他再看看.
create table table1(姓名 varchar(20))
insert  table1 select '王海'create table table2(姓名 varchar(20))
insert  table2 select '王海峰'select 姓名 from table1 where 姓名 in (select 姓名 from table2)
select 姓名 from table2 where 姓名 in (select 姓名 from table1)drop table table1,table2
/*
姓名                   
-------------------- (所影响的行数为 0 行)姓名                   
-------------------- (所影响的行数为 0 行)
*/

解决方案 »

  1.   

    --它们都只是一个属性的实例,是一个整体,不能用集合操作,可以如下:Select * from table1 as a
    where exists(
    select * from table2 where charindex(a.name,name)>0)
      

  2.   

    select 姓名 from table1 t
    where exists(select 1 from table2 where charindex(t.姓名,姓名)>0)or select A.姓名 
    from table1 A
    join table2 B on charindex(A. 姓名,B.姓名)>0
      

  3.   

    有可能是table2中的“王海峰”纪录后面多了一个半角的空格。导致
    select 姓名 from table2 的结果是王海,而不是王海峰。
    你可以尝试重新用insert加入王海峰这条纪录。
    检索的时候最好用
    select 姓名 from table1 where exists in (select * from table2 where table2.姓名=table1.姓名)
      

  4.   

    --测试语句, 这是不是你的要求,可以有多种方法
    create table table1(姓名 varchar(20))
    insert  table1 select '王海'create table table2(姓名 varchar(20))
    insert  table2 select '王海峰' Select * from table1 as a
    where exists(
    select * from table2 where charindex(a.姓名,姓名)>0)
    drop table table1,table2--结果姓名
    -----
    王海