sql,除了喜欢查询

时间:2018-07-06 11:55:42

标签: mysql sql

我希望搜索文章:

SELECT *
FROM articles
WHERE `body` LIKE `%src="http://%"

但是我想要除外:

src="//example.com"
src="//media.example.com"

我尝试:

SELECT *
FROM `articles`
WHERE `body` LIKE '%src="http://%' AND
      `body` NOT LIKE '%src="http://example.com%' AND
      `date_show` >= '2018-06-24'
LIMIT 20

但是我得到错误的结果。我该如何正确执行此操作?

1 个答案:

答案 0 :(得分:2)

SELECT * FROM `articles` WHERE `body` LIKE '%src="http://%' 
and  `body`  not in (SELECT body
FROM `articles` where `body` NOT LIKE '%src="http://example.com%' )  AND
      `date_show` >= '2018-06-24' LIMIT 20;