|
Posted by strawberry on 08/09/06 22:04
Brian wrote:
> Hi there
>
> Is it possible in one statement to check if an entry is there, if so update
> it if not then add it.
> I can do a normal by running a statement first but for reasons to long to go
> into I really would
> like it to all be done in one SQL statement
>
> e.g.
>
> if THIS is THERE then UPDATE IT WITH THIS if not there then ADD THIS NEW
> ENTRY
>
> Brian
Have a look at INSERT... ON DUPLICATE KEY UPDATE
Basically, as long as you have a UNIQUE or PRIMARY KEY on the
duplicatable fields then this syntax should work:
INSERT INTO table(field_a,field_b,field_c) VALUES
('value_a','value_b','value_c')
ON DUPLICATE KEY UPDATE a='value_a',b='value_b','c=value_c';
Navigation:
[Reply to this message]
|