mysql模糊查询

哎呦喂哈 2015-10-09 04:47:20
一条sql语句如何模糊查询多个字符串
比如我要把content字段里包含 aaaa、bbb、ccc、dddd 这几个字符串的数据排除掉
应该咋写
...全文
158 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
豫澜之利 2015-10-09
  • 打赏
  • 举报
回复
直接: 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%');
哎呦喂哈 2015-10-09
  • 打赏
  • 举报
回复
引用 1 楼 huiwenjie168 的回复:
SELECT * FROM TABLE WHERE content LIKE '%aaaa%' AND content LIKE '%bbb%' AND content LIKE '%ccc%' AND content LIKE '%dddd%'
最起码你用个or不应该用and吧 有简单点的吗,aaa、bbb、ccc是select语句查出来的,不是死的
  • 打赏
  • 举报
回复
引用 2 楼 u010425898 的回复:
最笨的方法: select content from A where content not like 'aaaa' and content not like 'bbb' and content not like 'ccc'
忘了给加%了,补上
  • 打赏
  • 举报
回复
最笨的方法: select content from A where content not like 'aaaa' and content not like 'bbb' and content not like 'ccc'
Cactus_hxk 2015-10-09
  • 打赏
  • 举报
回复
SELECT * FROM TABLE WHERE content LIKE '%aaaa%' AND content LIKE '%bbb%' AND content LIKE '%ccc%' AND content LIKE '%dddd%'

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧