Search code examples
mysqlreplacesql-like

MYSQL Replace Like doesn't Work


I have a problem with a query:

UPDATE 
    `MY_COLOR` 
SET 
    `Color` = REPLACE(`Color`, ' ', '') 
WHERE 
    `Color` LIKE ('L %')

The same query without "WHERE Color LIKE ('L %')" work.

Error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `MY_COLOR` WHERE `Color` LIKE ( 'L %' )' at line 3

Solution

  • you have a syntax error in LIKE clause. Use SELECT * FROM TABLE WHERE field1 like '%abc%'; So in your case, it will be
    UPDATE MY_COLOR SET Color = REPLACE(Color, ' ', '') WHERE Color LIKE 'L %';