like 中如何使用 in

qingniao8 2011-07-11 04:53:48
t1
----------------
data_id

sdfsdf45656
rthtr565122
12354546565
56566444444
xcv32344344

t2
-----------
data

65122
44344

结果
------------
data data_id
65122 rthtr565122
44344 xcv32344344

--------------
请问这个查询应该如何写啊,谢谢!
...全文
131 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yubofighting 2011-07-11
  • 打赏
  • 举报
回复

select data,data_id=(select data_id from t1 where data_id like '%'+t2.data+'%') from t2
qingniao8 2011-07-11
  • 打赏
  • 举报
回复
速度好快啊~~~结贴~
chuanzhang5687 2011-07-11
  • 打赏
  • 举报
回复
select a.*,b.* from t1 a inner join t2 b on a.data_id like '%'+b.data+'%'
-晴天 2011-07-11
  • 打赏
  • 举报
回复
create table t1(data_id varchar(20))
insert into t1 select
'sdfsdf45656' union all select
'rthtr565122' union all select
'12354546565' union all select
'56566444444' union all select
'xcv32344344'
create table t2(data varchar(10))
insert into t2 select '65122' union all select
'44344'
go
select a.*,b.* from t1 a inner join t2 b on a.data_id like '%'+b.data+'%'
/*
data_id data
-------------------- ----------
rthtr565122 65122
xcv32344344 44344

(2 行受影响)

*/
go
drop table t1,t2

浪子-无悔 2011-07-11
  • 打赏
  • 举报
回复
模糊查询~
bancxc 2011-07-11
  • 打赏
  • 举报
回复
charindex
GoAwayZ 2011-07-11
  • 打赏
  • 举报
回复
select * from t1 a, t2 b where charindex(a.data,b.data_id)>0
AcHerat 元老 2011-07-11
  • 打赏
  • 举报
回复

select a.data,b.data_id
from t2 a,t1 b
where b.data_id like '%'+a.data+'%'

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧