ANSI SQL question - how to insert or update a record if it already exists?
- by morpheous
Although I am using mySQL (for now), I dont want any DB specific SQL.
I am trying to insert a record if it doesn't exist, and update a field if it does exist. I want to use ANSI SQL.
The table looks something like this:
create table test_table (id int, name varchar(16), weight double) ;
//test data
insert into test_table (id, name, weight) values(1,'homer', 900);
insert into test_table (id, name, weight) values(2,'marge', 85);
insert into test_table (id, name, weight) values(3,'bart', 25);
insert into test_table (id, name, weight) values(4,'lisa', 15);
If the record exists, I want to update the weight (increase by say 10)