The below query is not good, due to the fact that if name and age aren't unique, I'll be returning multiple ids with it. One should always use the LAST_INSERT_ID() or after an insert, select max(id) from myTable.
-----Original Message----- From: Carter, Scott [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 18, 2003 12:59 PM To: 'Jonas Geiregat'; 'Mysql' Subject: RE: @@identity This may not be the correct solution exactly, but what I do to ensure that I get the correct ID back is the following: I know what I just inserted, therefore I can use this information in a WHERE clause to ensure retrieving the correct ID. Example: INSERT name='scott', age=20 into myTable WHERE ........; then SELECT id FROM myTable WHERE name='scott' AND age=20; Just one idea, someone might have a more efficient solution, afterall this is a common pattern! - Scott Carter -----Original Message----- From: Jonas Geiregat [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 18, 2003 1:37 PM To: 'Mysql' Subject: @@identity I'm using php + mysql for my project I want to get the last insert ID. I could use the php function mysql_last_id(); but I could aslo use @@identity. Now some people have advised me NOT to use @@identity, cause it's not save buggy sometimes slow .. is this true am I better of with the php function ? also I do my query insert something after that query I do an other query to get the last insert ID, if someone else does a insert query between those 2 query's won't that affect my last insert ID and won't I get the wrong one ? -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]