Afficher un message
Vieux 04/01/2008, 15h27   #2
ZeldorBlat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Return Values from INSERT

On Jan 4, 7:59 am, Taliesin Nuin <T.N...@bath.ac.uk> wrote:
> This is probably a daft question. I want to know if there is a way to get
> a primary key value back from an INSERT statement for later use, without
> having to do a second query afterwards.
>
> I have a table that references the keys of values in two other tables and
> I want to add a row to it using the key values looked up from the other
> tables in SELECT sub-clause. That's okay, but sometimes these other
> tables wont have a matching entry in which case I want to create one. Is
> it possible to do this in one go, i.e. by putting an INSERT...ON
> DUPLICATE KEY UPDATE statement in the sub-clause and returning the
> affected row?
>
> I hope that's clear. The data that might need to be inserted matches the
> data searched on so it just seems a shame to break it up into multiple
> queries when just knowing the primary key of the affected row would let
> me pile everything into one statement, so I thought there might be a way
> to do this. Am quite new to MySQL.
>
> Thanks,
>
> -Taliesin.


Whoa, in the MySQL manual I found this page titled "How to Get the
Unique ID for the Last Inserted Row." Sounds like it might be
relevent to your problem.

<http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html>
  Réponse avec citation
 
Page generated in 0,05061 seconds with 9 queries