Reputation: 26511
I want to filter result of my SQL query. I want to select everything that has some specific text in some column.
Example:
SELECT * FROM categories WHERE (name has 'abc' values in it's value ex. MyabcCategory)
Also maybe it is not very good idea to do that in query, maybe it is better to get all and then filter array instead? But I don't know how to do that aether.
Upvotes: 1
Views: 195
Reputation: 401152
You want to use the LIKE
operator, with %
to match any character before and after your specific word :
select *
from categories
where name like '%abc%';
But note that doing so, MySQL will scan each line of the table, every time the query is executed... which might not be great if you have a lot of data.
If you're searching for some kind of text, you might either want to :
FULLTEXT
index, if you're working with MyISAM tables.Upvotes: 3
Reputation: 382806
Use LIKE
with %
wildcard:
SELECT * FROM categories WHERE name LIKE '%abc%'
This will give you all the records that have abc
somewhere in them.
You can learn more about it here :)
Upvotes: 5