MySQL – Using a Column Name Inside the LIKE Keyword

When using the LIKE keyword in a MySQL query, I use it the most typical way, LIKE ‘%STRING%’. One day, I was in need to use a column name instead and could not figure out how to do it! At first, I tried to just replace the string value with the column name like this, LIKE (%t.column%). The end-result was not good as the LIKE keyword expects a string.

So, I thought of trying the CONCAT() function since that returns a string. And it worked!

Hope this helps someone!

5 thoughts on “MySQL – Using a Column Name Inside the LIKE Keyword”

  1. It helped me to quickly solve the problem when string variable that I was putting into the query from the search-field had the value ‘And1’ (company name). Thanks a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *