当前位置: 代码迷 >> Java Web开发 >> mysql模糊查询,该如何处理
  详细解决方案

mysql模糊查询,该如何处理

热度:84   发布时间:2016-04-13 22:18:08.0
mysql模糊查询
一条sql语句如何模糊查询多个字符串
比如我要把content字段里包含  aaaa、bbb、ccc、dddd  这几个字符串的数据排除掉
应该咋写

------解决思路----------------------
SELECT * FROM TABLE WHERE content LIKE '%aaaa%' AND content LIKE '%bbb%' AND content LIKE '%ccc%' AND content LIKE '%dddd%'
------解决思路----------------------
最笨的方法:
select content from A where content not like 'aaaa' and content not like 'bbb' and content not like 'ccc'
------解决思路----------------------
直接:
select * from table where  content not like '%aaaa%' orcontent not like '%bbb%' orcontent not like '%ccc%' orcontent not like '%dddd%';
或者麻烦些:
select * from table where id not in (select id from table where content like '%aaaa%' and content like '%bbb%' and content like '%ccc%' and content like '%dddd%');
  相关解决方案