MySQL: NOT LIKE

后端 未结 2 402
半阙折子戏
半阙折子戏 2021-01-31 01:17

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

相关标签:
2条回答
  • 2021-01-31 02:04

    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')
    
    0 讨论(0)
  • 2021-01-31 02:17

    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:

    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%'
    
    0 讨论(0)
提交回复
热议问题