34,838
社区成员




select distinct a.*
from aaa a,sss b
where a.phone like '%'+b.tel+'%'
select phone from aaa where exists(
select 1 from sss where aaa.phone LIKE '%' + RTRIM(tel) + '%'
)
select phone from aaa where exists(
select 1 from sss where charindex(tel,aaa.phone)>0
)
--这样肯定没错了啊,如果有错就是你数据的问题
select phone from aaa t where exists(select 1 from sss where tel=t.phone)
create table sss(tel varchar(11))
insert into sss
select '11111111111' union all
select '22222222222' union all
select '33333333333' union all
select '44444444444'
create table aaa(phone varchar(20))
insert into aaa
select '11111111111' union all
select '22222222222' union all
select '33333333333' union all
select '44444444444' union all
select '020-56893685' union all
select '13913801380' union all
select '020-56893685' union all
select '13913801380'
select * from aaa where phone in (select tel from sss)
phone
------------
11111111111
22222222222
33333333333
44444444444
--貌似需求看反了,改下
select phone from aaa where exists(
select 1 from sss where tel=aaa.phone
)
[Quote=引用 2 楼 geniuswjt 的回复:]
select tel from sss where exists(
select 1 from aaa where phone=sss.tel
)
select a.*
from aaa a,sss b
where b.tel like '%'+a.phone+'%'