MySQL uses another field for fuzzy query
P粉333186285
P粉333186285 2023-07-25 11:34:12
0
2
415

I have a table with two string columns: Url and ModelId. I need to return those records whose URL contains ModelId, similar to this query:

SELECT Id, Url, ModelId WHERE Url like "%ModelId%"


P粉333186285
P粉333186285

reply all (2)
P粉418351692

You can't just concatenate strings, you must also escape the fields, using the special characters % and _:

SELECT Id, Url, ModelId WHERE Url LIKE CONCAT('%', REPLACE(REPLACE(ModelId,'%','\%'),'_','\_'), '%'), '%')
    P粉199248808
    SELECT Id, Url, ModelId WHERE Url LIKE CONCAT('%', ModelId, '%')
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!