1

I'm trying to run the following statement:

INSERT INTO table (
    as,
    ad
    ,af,
    ag,
    ah,
    aj
)                                       
VALUES (
    'a',
    'b',
    'c',
    'd',
    'e',
    'f'
)
ON DUPLICATE KEY UPDATE (
    aj='dv',
    ah='ev',
    ag='fv'
);

and getting the following error:

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 '(ag='dv',ah='ev',ah='fv')' 
at line 3

Any advice?

thx

Adam
  • 19,932
  • 36
  • 124
  • 207

1 Answers1

5

Skip the ()..

 INSERT INTO site_domains_meta 
 (domainname,metatype,pagename,english,indonesian,japanese)
  VALUES ('a','b','c','d','e','f')
  ON DUPLICATE KEY UPDATE english='dv',indonesian='ev',japanese='fv';

http://dev.mysql.com/doc/refman/5.5/en/insert.html

barsju
  • 4,408
  • 1
  • 19
  • 24
  • 1
    As an addition, you can use VALUES() instead of re-specifying data, i.e. `ON DUPLICATE KEY UPDATE english = VALUES(english), indonesian = VALUES(indonesian), japanese = VALUES(japanese)` as then it can update multiple-row inserts too with the correct values – Simon at The Access Group Apr 20 '12 at 10:49
  • 1
    perfect... thx... will tick once the time limit expires... cheers – Adam Apr 20 '12 at 10:49