You are here: Re: Check then Add / Update « PHP SQL « IT news, forums, messages
Re: Check then Add / Update

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация