Search code examples
mysqlsqlsql-like

MySQL LIKE Statement not working


I'm trying to copy data from one table to another.

Here is my statement:

UPDATE tblMerchants T,
       retailers R 
   SET T.linklabel = R.linklabel,
       T.logo_image = R.logo_image,
       T.screen_image = R.screen_image,
       T.category = R.category,
       T.meta_description  = R.meta_description,
       T.meta_title = R.meta_title,
       T.meta_keywords = R.meta_keywords,
       T.intro = R.intro,
       T.permalink = R.permalink,
       T.excerpt = R.excerpt,
       T.main_link = R.main_link,
       T.related_blog_post = R.related_blog_post,
       T.active = R.active, 
       T.homepage_featured = R.homepage_featured 
 WHERE T.homepageurl LIKE '%R.linklabel%'

For example, T.homepageurl would look like http://www.amazon.com/ and R.linklabel would look like amazon.com. So I can't figure out why its not working. I'm not getting any errors, its just saying 0 rows affected.


Solution

  • You should be able to use CONCAT to do this:

    WHERE T.homepageurl LIKE CONCAT('%', R.linklabel, '%');
    

    The concat function is used to concatenate multiple strings together. The reason why it's not working is because it's trying to match "http://www.amazon.com" with "%R.linklabel%" instead of "amazon.com".