Hello,

I'm looking for a solution to write a sql query that inserts a set of data if the data 
id is not present and otherwise update the set.

I have a table with id (char(8)) and value (int(8))

To make my problem clear:

There is no set with id = "20030713"
insert into table values ("20030713","10");

The next set is ("20030713","20") but as a set with 20030713 is already available I 
like to have
update table set value = value + 20 where id = "20030713"

I tried the "replace" command but I fail to get the "value = value + 20" working.

The problem is that the query is called from within a programm that only can call a 
query but not get some data back.

Also a solution in form of

mysql>
$w = select value from table where id = "20030713";
delete from table where id = "20030713";
insert into table values ("20030713",$w + 20);
<mysql

would be fine but I think that $w = part isn't working with mysql ;-)

Its no solution to simply make the table accept duplicate entries for id and make a 
"sum(value) group by id" because I think it will be a performace problem if I have 
thousends of datasets a day - If I'm wrong let me know.

Any hints how to manage this??

Alexander Newald

Reply via email to