日期:2014-05-17  浏览次数:20362 次

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 a
where exists(select 1 from b where charindex(','+ltrim(b.b)+',',','+a.a+',')>0)