Search code examples
mysqlsyntax-errormysql-error-1064

MySQL syntax error - obvious?


Can anyone spot the syntax error in this thing?

UPDATE `inventory` 
LEFT JOIN `manufacturers` ON (
  `man_id` = `manufacturers`.`id`
)
LEFT JOIN `meta_tags` ON (
  `meta_tags`.`page_url` = REPLACE(REPLACE(`manufacturers`.`title`, " ", "_"), "\", "_")
)
SET `inventory`.`tag_ids` = CONCAT_WS("," `tag_ids`, `tag_id`)
WHERE FIND_IN_SET(`tag_id`, `tag_ids`) = 0

Error message:

 #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 
 '_" ) ) SET `inventory`.`tag_ids` = CONCAT_WS("," `tag_'

Solution

  • You probably need to escape the \ in your outer REPLACE() function. Try using

    REPLACE(REPLACE(`manufacturers`.`title`, " ", "_"), "\\", "_")
    

    in place of what you have. Here's the MySQL reference explaining character escape sequences.