mysql@lists.mysql.com ----- Original Message ----- From: Sebastian Mendel <[EMAIL PROTECTED]> To: Richard <[EMAIL PROTECTED]> Cc: <mysql@lists.mysql.com> Sent: Wednesday, October 31, 2007 3:11 PM Subject: Re: Inserting a value in an autoincrement list?
> Richard schrieb: > > I want to have a list of titles to which I can add new ones either at > > the end of the list or in a chosen position so I can choose what order > > they show up in. > > > > The first solution that I thought of was to add one to all of the > > position values heigher than the position I wish to insert the new one > > to. But this would envolve alot of queries and therefore resources. > > > > So now I'm wandering if it is possible to do this directly with mysql. > > Here is an example of what I want to do > > I will have a table called titles like this : > > > > -------------------------------- > > table : title > > ------------------------------- > > POSTITION | TITLE > > 1 | title joejjeo > > 2 | title ejuejej > > 3 | title ekkke > > 4 | title eueoueo > > 5 | title eehiehiehop > > > > > > And I wish to insert : > > > > 3 | title inserted > > > > So that titles in positions 3, 4 and 5 become titles 4, 5 and 6 > > > just two queries: > > UPDATE `title` > SET `POSTITION` = `POSTITION` + 1 > WHERE `POSTITION` > 2; > > INSERT ...; > > -- > Sebastian > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] > > -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]