mysql query question

Alexander Newald alexander at newald.de
Tue Jul 15 04:05:08 PDT 2003


""Alexander E. Patrakov"" <semzx at newmail.ru> schrieb im Newsbeitrag
news:200307150934.59928.semzx at newmail.ru...
> On Sunday 13 July 2003 07:30, Alexander Newald wrote:
> > Hello,
> >
> > I know that it is not really blfs related but I had no sucsess
elsewhere:
> >
> > How do I manage to get "if exists UPDATE else INSERT" in mysql working?
> > replace is not the solution.
> >
> > Thanks,
> >
> > Alexander Newald
>
> http://www.mysql.com/doc/en/REPLACE.html
>
> REPLACE works exactly like INSERT, except that if an old record in the
table
> has the same value as a new record on a UNIQUE index or PRIMARY KEY, the
old
> record is deleted before the new record is inserted. See section 6.4.3
INSERT
> Syntax.
>
> -- 
> Alexander E. Patrakov

I forgett to say that I need to update one row like a = a + 10 that replace
can't do.

A solution is:

set @w = 0;
select @w := value from table where id = "20030713";
delete from table where id = "20030713";
insert into table values ("20030713", @w + 20);

if someone is interested in it too

Alexander Newald


-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe blfs-support' in the subject header of the message



More information about the blfs-support mailing list