Re: Multiple Statements in a query



..oO(Ivan Marsh)

On Fri, 02 Mar 2007 11:28:02 -0800, paladin.rithe@xxxxxxxxx wrote:

I have 2 statements that I'd like to string together in a query, but
according to everything I'm seeing, it's not possible.
What I'm doing is an insert of a row, where the primary key is an auto
increment. I want to retrieve that by using LAST_INSERT_ID(). I
tried sending another query after the first (once I knew that it the
data was what I need) but it didn't return anything. It seems that
that function can't be used in separate calls or something. Either
that or there's a setting that I need to check. Any ideas?

Neither nor, there's an error in your second query. Please post some
code and the used query.

If you're trying to return the last inserted row on a table with an auto
increment field all you have to do is query the maximum value in that
field.

Wrong! Never do it that way, never! Google for "race condition" and you
will know why. The correct way to do it is to call LAST_INSERT_ID(),
either natively in a query or through a higher API function like
mysql_insert_id().

Micha
.



Relevant Pages

  • Re: Append to table
    ... The problem appeared to be that I had not set the key fields increment ... I have an append query that adds a record to a Table. ...
    (microsoft.public.access.forms)
  • Re: Plus One Button on Form
    ... "John W. Vinson" wrote: ... Dont get me wrong, of course there are tables in my DB and this is where all ... I was thinking of making a query for the 'plus ... What value do you want to increment? ...
    (microsoft.public.access.forms)
  • Re: assign numbers to the occurence of data
    ... >> will make the query run a bit slowly): ... >>> start at 1 and increment up to the count of the data. ...
    (microsoft.public.access.macros)
  • Re: Plus One Button on Form
    ... "John W. Vinson" wrote: ... Dont get me wrong, of course there are tables in my DB and this is where all ... I was thinking of making a query for the 'plus ... What value do you want to increment? ...
    (microsoft.public.access.forms)
  • Re: Append query with addtional fields
    ... incremented value within the query records. ... Public lng As Long ... Public bln As Boolean ... I can't quite figure out how to increment the numbers in the ...
    (microsoft.public.access.queries)