本帖最后由 acelove 于 2012-11-29 13:51:07 编辑 表TAB_A存放格式如下
NO KEYWORDS
1 11
2 22
3 33
4 44
表TAB_B存放格式如下
ID KEYWRODS
A1 11,66,88
A2 99,55,878
A3 22,33,44
A4 00,000,0000
如何通过表TAB_A的KEYWORDS查询出TAB_B中包含表TAB_A的KEYWORDS的数据
正确显示应该是表TAB_B中A1和A3数据
ID KEYWRODS
A1 11,66,88
A3 22,33,44
------最佳解决方案--------------------
select * from TAB_B
where exists(select 1 from TAB_A where ','+TAB_B.KEYWRODS+',' like '%,'+KEYWORDS+',%')
------其他解决方案--------------------
select distinct b.* from a,b where charindex(','+a.KEYWORDS+',',','+b.KEYWORDS+',')>0
------其他解决方案--------------------
select distinct b.*
from TAB_A a
join TAB_B b on charindex(','+ltrim(a.KEYWORDS)+',',','+b.KEYWRODS+',')>0
------其他解决方案--------------------
谢谢各位兄弟帮忙
------其他解决方案--------------------
select distinct b.* from a,b where charindex(','+a.KEYWORDS+',',','+b.KEYWORDS+',')>0