MySQL:不喜欢
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5346859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL: NOT LIKE
提问by laukok
I have these text in my db,
我的数据库中有这些文本,
categories_posts
categories_news
posts_add
news_add
And I don't want to select the rows with categories
, I use a query something like this,
我不想用 选择行categories
,我使用这样的查询,
SELECT *
FROM developer_configurations_cms
WHERE developer_configurations_cms.cat_id = '1'
AND developer_configurations_cms.cfg_variables LIKE '%parent_id=2%'
AND developer_configurations_cms.cfg_name_unique NOT LIKE '%categories%'
but it returns these two in the output as well...
但它也会在输出中返回这两个......
categories_posts
categories_news
How can I ignore them in my query?
如何在查询中忽略它们?
Thanks.
谢谢。
回答by Dalen
categories_posts
and categories_news
start with substring 'categories_' then it is enough to check that developer_configurations_cms.cfg_name_unique
starts with 'categories' instead of check if it contains the given substring. Translating all that into a query:
categories_posts
并categories_news
以子字符串“categories_”开头,然后检查developer_configurations_cms.cfg_name_unique
以“categories”开头的内容就足够了,而不是检查它是否包含给定的子字符串。将所有这些翻译成一个查询:
SELECT *
FROM developer_configurations_cms
WHERE developer_configurations_cms.cat_id = '1'
AND developer_configurations_cms.cfg_variables LIKE '%parent_id=2%'
AND developer_configurations_cms.cfg_name_unique NOT LIKE 'categories%'
回答by Piotr Salaciak
I don't know why
我不知道为什么
cfg_name_unique NOT LIKE '%categories%'
still returns those two values, but maybe exclude them explicit:
仍然返回这两个值,但可能明确排除它们:
SELECT *
FROM developer_configurations_cms
WHERE developer_configurations_cms.cat_id = '1'
AND developer_configurations_cms.cfg_variables LIKE '%parent_id=2%'
AND developer_configurations_cms.cfg_name_unique NOT LIKE '%categories%'
AND developer_configurations_cms.cfg_name_unique NOT IN ('categories_posts', 'categories_news')