MySQL: Using Column Name Inside The LIKE Keyword
Posted by tech on
February 22, 2009
When using the LIKE keyword, I always get to do it this way, LIKE (‘%STRING%’). When the time came for me to use a column name instead since all string values to search for is in a table in my database, I tried to just replace the string value with the column name like this LIKE (%table.column_name%). The result was pretty obvious. It gave me an error.
As a string is required in this situation, I thought of trying the CONCAT() function since that outputs a string. And it worked! Hehehe. You can do it like this
1 | LIKE CONCAT('%', table.column_name) |









March 7th, 2011 at 7:50 pm
@voodoo
have you try this
LIKE CONCAT(‘%’,table.column_name,’%')
October 9th, 2011 at 11:14 am
great post..thanks for share!