开发者

MySQL - Filter result

开发者 https://www.devze.com 2023-02-13 06:08 出处:网络
I want to filter result of my SQL query. I want to select everything that has some specific text in some column.

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

精彩评论

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