1 Vote Vote

MySql Table Insert if not exist otherwise update

Posted by topdog 372 days ago Questions| insert update otherwise All
UPDATE AggregatedData SET datenum="734152.979166667", 
Timestamp="2010-01-14 23:30:00.000" WHERE datenum="734152.979166667";

It works if the datenum exists, but I want to insert this data as a new row if the datenum does not exist.

UPDATE

the datenum is unique but that's not the primary key

Originally asked by: iUngi on Stack Overflow

1 Answer Bury


Who Voted for this Question



Answers

comment-avatar
topdog
372 days ago
You may want to use something like:

INSERT INTO table (a,b,c) VALUES (1,2,3)

ON DUPLICATE KEY UPDATE c=c+1;
Rating: 0   up down

Log in to answer or register here.