0

I have a fifteen-column table in my database.

and I have a key which has a quality of auto-increment.

What I want to do is.. check if the table has a column with the key and insert if exist, else update.

I applied SQL syntax which I found here to my code.. but it never works.

here's the sample code below.

    insert into report (col1, col2, col3.......col14) values ('value1','value2', ....'value14')
ON DUPLICATE KEY UPDATE col1=values('changedValue1'), col2=values('changedValue2')....col14=values('changedValue14');

I excuted this code in Mybatis, but it returns MySQLSyntaxErrorException..

Leo
  • 822
  • 2
  • 11
  • 22

1 Answers1

1

you have syntax error in your query.the query should be like,

insert into report (col1, col2, col3.......col14) values ('value1','value2', ....'value14')
ON DUPLICATE KEY UPDATE col1='changedValue1', col2='changedValue2'....col14='changedValue14';

for more info visit the following link : Insert into a MySQL table or update if exists

Vibha Chosla
  • 733
  • 5
  • 12