Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I am having these texts in my database,

categories_posts
categories_news
posts_add
news_add

And I don't need to select the rows with categories, I use the query something like this,

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%'

Though it returns these two in the output as well..

categories_posts
categories_news

How can I ignore them in my query?

1 Answer

0 votes
by (12.7k points)

"categories_posts" and  "categories_news" begin with the substring "categories_" and then it is adequate to check that "developer_configurations_cms.cfg_name_unique" begins with "categories" rather than check if it has the given substring. Translating all that into the 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%'

 Looking for a SQL Tutorial? Join the SQL Course to gain more knowledge on SQL.

Related questions

0 votes
1 answer
asked Nov 21, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
+2 votes
1 answer
0 votes
1 answer

Browse Categories

...