最主要的是想问假如我要查询word含有'csdn'或'msdn'或'msam'或...的id,sql语句应该怎么写比较好 改为-> 假如我要查询word='a'或'c'或'd'或...所对应的id,sql语句应该怎么写比较好 例如上面的表,我通过查询word='a' 找出了id=1 or 3,然后通过id再去找word='c'的id(这个过程是一个语句或存储过程完成的) 哎,希望我的问题大家明白了
select count(*) from table group by docid,word where word like '%csdn%' or word like '%msdn%' or word like '%masm%'
select * from table where word like '%csdn%' or word like '%msdn%' or word like '%masm%'
不好意思,大家理解错我的意思了,我是想要达到这种效果: select id,word from table where id in ( select id from table where id in ( select id from table where word='csdn' ) and word='msdn' ) and word='msam' 我觉得要这样子嵌套的话实在太慢了,请问有什么好的优化思路吗?
select id,word from table a left join table b a.id=b.id where a.word='csdn' and b.word='msdn'
改为->
假如我要查询word='a'或'c'或'd'或...所对应的id,sql语句应该怎么写比较好
例如上面的表,我通过查询word='a' 找出了id=1 or 3,然后通过id再去找word='c'的id(这个过程是一个语句或存储过程完成的)
哎,希望我的问题大家明白了
where word like '%csdn%' or word like '%msdn%' or word like '%masm%'
from table
where word like '%csdn%' or
word like '%msdn%' or
word like '%masm%'
select id,word from table where id in
(
select id from table where id in
(
select id from table where word='csdn'
)
and word='msdn'
)
and word='msam'
我觉得要这样子嵌套的话实在太慢了,请问有什么好的优化思路吗?
where a.word='csdn' and b.word='msdn'