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!
LIKE CONCAT('%', t.column)
Hope this helps someone!
This was so useful!...
This was so useful!
It helped me to quickly solve...
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!
Post new comment