--我测试了,语句是对的,也没出现你说的情况,他再看看.
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 行)
*/
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 行)
*/
where exists(
select * from table2 where charindex(a.name,name)>0)
where exists(select 1 from table2 where charindex(t.姓名,姓名)>0)or select A.姓名
from table1 A
join table2 B on charindex(A. 姓名,B.姓名)>0
select 姓名 from table2 的结果是王海,而不是王海峰。
你可以尝试重新用insert加入王海峰这条纪录。
检索的时候最好用
select 姓名 from table1 where exists in (select * from table2 where table2.姓名=table1.姓名)
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--结果姓名
-----
王海