MySQL: Using Column Name Inside The LIKE Keyword

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)

Donations appreciated. Every little $ helps. Or click Google +1

Related Posts with Thumbnails

tags: , ,

7 Responses to “MySQL: Using Column Name Inside The LIKE Keyword”

Pages: « 1 [2] Show All

  1. 6
    steve Says:

    @voodoo

    have you try this

    LIKE CONCAT(‘%’,table.column_name,’%')

  2. 7
    best mac games Says:

    great post..thanks for share!

Pages: « 1 [2] Show All

Leave a Reply

Spam protection by WP Captcha-Free