首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql语句该如何写

2012-09-20 
sql语句该怎么写有两张表A,BA表有一个字段a,字符串型id name a1li112,113,1142wang 113,115...B表idb11112

sql语句该怎么写
有两张表A,B

A表有一个字段a,字符串型
id name a
1 li 112,113,114
2 wang 113,115
...

B表
id b
1 111
2 112
3 113
...

现在想要查找A表中的一些记录,条件是B表中的b集合中只要有一个存在于a字段中,就找出来。
大致是select * from A where (select b from B) in a 这个意思,但是具体的不会写,请大虾指教。

[解决办法]
select a.*
from a join b on charindex(name,b)>0
[解决办法]

SQL code
select a.* from awhere exists(select 1 from b where charindex(','+ltrim(b.b)+',',','+a.a+',')>0) 

热点排行