开发者

MySQL - Filter result

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 categori开发者_Python百科es 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.


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 :)


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 :

  • Use a FULLTEXT index, if you're working with MyISAM tables.
  • Or, use a solution that's separated from MySQL, with a specific indexing/search engine, such as Solr.


SELECT * FROM categories WHERE name LIKE '%abc%'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜