How to check if a string contains any string of a column in MySQL and vice versa?

爷,独闯天下 提交于 2019-12-12 18:27:05

问题


By vice versa, I mean, check if any of the strings in a column contains the string.

Example:

String a = "Peperoni"

MySQL column:

{
    "PPeperoni_123",
    "roni",
    "hello world"
}

It should return the first 2 rows.

(Note: im looking for the query string for this)


回答1:


Not sure if I understand you correctly, but are you maybe looking for this:

SELECT ... WHERE column LIKE "%string%" OR string LIKE CONCAT("%", column, "%")



回答2:


with Mysql you can use SOUNDS LIKE to find the nearest matches

example

SELECT * FROM table WHERE column SOUNDS LIKE 'Peperoni' ;



来源:https://stackoverflow.com/questions/15862257/how-to-check-if-a-string-contains-any-string-of-a-column-in-mysql-and-vice-versa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!