"Scott Purcell" <[EMAIL PROTECTED]> wrote on 03/04/2005 01:42:40 PM:
> UPDATE menu_sequence SET id=LAST_INSERT_ID(id+1); > > > I am writing some code that I need to actually get the menu_sequence > from above, store it in a variable and then do a increment. I do > not know why I am having trouble with this, but it looks like I would have to > String seq = "select id from menu_sequence" > use seq, > then > String update = "update menu_sequence set id=last_insert_id(id+1) > > The reason is, I need to use the "seq" variable to create a true ID > using some other algorithms. Anyway is there a better or simpler way > to do this? I hate to do two queries and then I have to worry about > synchronization. > > thanks, > Scott > > > Scott K Purcell | Developer | VERTIS | > 555 Washington Ave. 4th Floor | St. Louis, MO 63101 | > 314.588.0720 Ext:1320 | [EMAIL PROTECTED] | http://www.vertisinc.com < > http://www.vertisinc.com/> > > Vertis is the premier provider of targeted advertising, media, and > marketing services that drive consumers to marketers more effectively. > > > If you wanted to know the last ID value generated in your session you need to use the LAST_INSERT_ID() function. LAST_INSERT_ID() is connection specific so you don't run the risk of getting someone else's most recently generated value. Is that what you were worried about when you mentioned "synchronization" ? Details --> http://dev.mysql.com/doc/mysql/en/information-functions.html What exactly are you trying to achieve? If you could be a little more specific, we could be more helpful. Shawn Green Database Administrator Unimin Corporation - Spruce Pine