Skip to content
Advertisement

SQL – Select records where columns include the keyword and have the same category

I’m working on a search bar. I have two fields category and input. If the user types the query and doesn’t select a category

I want to get all records matching the keyword. I’ve done it and it’s working perfectly.

Now If the user select a category with the keyword. I want get records where category is user’s selected category.

The query above doesn’t return records with the same category.

I have a categories column in mytable and there can be multiple categories

like so

How can I do this?

Advertisement

Answer

You need to make proper use of parentheses here to get the correct logical order you intend:

The version you had was actually using this WHERE clause:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement