From: Jochen Haeberle Date: March 16 1999 10:45pm Subject: Re: Can I get a field when inserting a row? List-Archive: http://lists.mysql.com/mysql/354 Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" ; format="flowed" At 14:36 Uhr -0700 16.03.1999, Thimble Smith wrote: > On Tue, Mar 16, 1999 at 10:20:20PM +0100, Jochen Haeberle wrote: >> thanks for your helping efforts, but it does not work. When I enter > The last insert id is stored *per thread*, not per table. When > you select LAST_INSERT_ID(), it checks your thread for the most > recent ID inserted. This is critical for correct performance of > programs, because more than one thread can be updating a table. > If LAST_INSERT_ID() returned the most recent ID for a table, you > could not be sure it belonged to the row you just inserted or a > row that someone else inserted. Ah thank you, that helps. Is a thread every instance of for example 'mysql' or is there some way to make sure I get the ID belonging to the correct row? > > Since you just went into the 'mysql' program (which started a > new thread) and then issued 'SELECT LAST_INSERT_ID()', there was > no previous id inserted for your thread. If you try inserting > a row and then selecting LAST_INSERT_ID() right afterwards (i.e., > without quitting the 'mysql' program), you will get back the ID > that was just created. > >> I tried >> >> select LAST_INSERT_ID(Insert Into Item (Name) Values ('Test')); >> >> this would be the perfect syntax for my problem, but I got >> >> ERROR 1064: parse error near 'Insert Into Item (Name) Values >> ('Test'))' at line 1 > > You really should be familiar with SQL to some degree. All of > the syntax of MySQL is described in the manual. If it's not in > the manual, it won't work! I am trying to get familiar with SQL. The MySQL-Manual really is not much help for an unexperienced guy like me. I am awaiting the O'Reilly Book on MySQL/mSQL to be delivered, hopefully, that will help. As Last_Insert_ID() seems to be a function, what can be passed to the function when the code I tried is not permitted. Jochen