MySQL like another field

SiberianGuy picture SiberianGuy · Feb 3, 2011 · Viewed 27.2k times · Source

I have a table with two string columns: Url and ModelId. I need to return records for which Url contains ModelId, something like this:

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

Answer

Michael Robinson picture Michael Robinson · Feb 3, 2011
SELECT Id, Url, ModelId 
WHERE Url LIKE CONCAT('%', ModelId, '%')