ANSI SQL question - how to insert or update a record if it already exists?
        Posted  
        
            by morpheous
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by morpheous
        
        
        
        Published on 2010-04-18T13:48:43Z
        Indexed on 
            2010/04/18
            13:53 UTC
        
        
        Read the original article
        Hit count: 368
        
sql
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)
© Stack Overflow or respective owner