Matei Gabriel Matei Gabriel - 1 month ago 5
MySQL Question

UPDATE syntax error for SET WHERE LIKE

UPDATE isc_products SET prodretailprice=145 WHERE prodcode LIKE TSACR3


I'm trying to update
prodretailprice
for all the products that have
prodcode
"TSACR3" but I keep getting this 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 '[TSACR3]' at line 1

HAL HAL
Answer
UPDATE `isc_products` SET `prodretailprice`=145 WHERE `prodcode` LIKE 'TSACR3'

Enclose the search pattern in single quotes.

LIKE syntax: http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like

LIKE can be used with the following wildcard characters

  • % Matches 0 or more characters. E.g. LIKE 'TSACR3%' will match TSACR3 bla blah
  • _ Matches exactly one character. E.g. LIKE '_TSACR3' will match 2TSACR3 but NOT 42TSACR3
Comments