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

13,229

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

SELECT ... WHERE column LIKE "%string%" OR string LIKE CONCAT("%", column, "%")
Share:
13,229
Zananok
Author by

Zananok

Updated on June 04, 2022

Comments

  • Zananok
    Zananok almost 2 years

    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)

  • Zananok
    Zananok about 11 years
    Thank you, that is exactly what I am looking for.
  • Zananok
    Zananok about 11 years
    Thank you, that also helps me on a similar issue.
  • aidonsnous
    aidonsnous over 8 years
    LIKE CONCAT("%", column, "%") is not secure if the value of the column contains %
  • aidonsnous
    aidonsnous over 8 years
    Sounds like can not return that result it compares string phonetically