日期:2014-05-19  浏览次数:20799 次

如果把字符串的子串作为查询条件?
为了表述方便,简化了下问题
两张表
表名               字段   字段       字段
[article1]   id1,   title1,content1
[article2]   id2,   title2,content2

想要在article1找出所有id2为12,25的title1为titile2的子串的记录,怎么找啊
上面的话好像有点拗口
意思就是先找出select   *   from   article1   where   id=12   or   id=25
然后在article1中找出上面记录集中title1为其子串的记录

谢了!

------解决方案--------------------
select a.* from article1 a,article2 b where (a.id=12 or a.id=25) and charindex(a.title1,b.title2)> 0
------解决方案--------------------
select * from article1 A
where exists
(select 1 from article1 B where B.id=12 or B.id=25 and A.id = B.id)