Reply to Re: [mysql] subquery and update

Your name:

Reply:


Posted by J.O. Aho on 10/14/72 11:46

Piotr wrote:
> I wanto set next max number from 'number' field +1 when I update any
> record. I tryied to do like this:
>
> UPDATE table set number=(select MAX(number)+1 from table) WHERE Id=122
>
> but I got error 1093
>
> How can I do it? It can't be autoincrement. I must be sure if nobody
> else got the same number in the same time.

Which version of MySQL?

You could try

SET @new=(SELECT MAX(t.number) FROM table t); UPDATE table SET VALUE=(SELECT
@new := @new+1) WHERE ID=1;



//Aho

[Back to original 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

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