Anna Åhnberg writes:
> Thanks, I actually already found the chapters but now I also now how to > use the function too! Let me quote from the manual: "LAST_INSERT_ID([expr]) Returns the last automatically generated value that was inserted into an AUTO_INCREMENT column. mysql> select LAST_INSERT_ID(); -> 195" Thus you'd follow these steps: 1) INSERT into the table, and leave out the auto column or supply a value of 0 or NULL 2) Verify that the query succeeded 3) SELECT LAST_INSERT_ID() 4) Get the result of the SELECT. On success, the SELECT will return one row with one value in it. That is the number you're interested in knowing. If you were using MySQL's C API there is a function that returns the ID without the need for steps 3-4, but since you are communicating over JDBC I don't think there's a simpler solution available. The query in step 3 is extremely fast, so it doesn't really matter, except that it's a bit more work to make an extra query. //C -- Carl Troein - Círdan / Istari-PixelMagic - UIN 16353280 [EMAIL PROTECTED] | http://pixelmagic.dyndns.org/~cirdan/ Amiga user since '89, and damned proud of it too. --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php