MySQL: Using Column Name Inside The LIKE Keyword
Posted by blogmeister 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) |
Share the post "MySQL: Using Column Name Inside The LIKE Keyword"










