Hello

Sometimes I get a duplicate key which I want to ignore or discard.

This is a example and has nothing to do with the actual query. I simple want to state columns/values

insert into table(Time_Stamp,Time_Stamp_ms,p1) values (time,timems,'1')

Where the first two are my PK.

I see that

insert into table(Time_Stamp,Time_Stamp_ms,p1) values (time,timems,'1') on duplicate key

exists but it asks me for a UPDATE. How do I update on "Time_Stamp" and "Time_Stamp_ms"?

Im sorry for not explaining correctly my problem.

Where the first two are my PK.

No need to update the PK's if they're the same:

insert IGNORE into table(Time_Stamp, Time_Stamp_ms, p1) values (time, timems, '1')

The above has as drawback that ALL errors are ignored.

or:

insert into table(Time_Stamp,Time_Stamp_ms,p1) values (time,timems,'1') on duplicate key update p1 = '1'

I figured it out:

insert into table(Time_Stamp,Time_Stamp_ms,p1,p2) values (time,timems,'1','2') on duplicate key update p1 = '1',p2='2'

That works for me. Did not know you could update more than one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.