Re: insert question
On Tue, Feb 24, 2009 at 8:53 PM, PJ af.gour...@videotron.ca wrote: Is there a way to insert several rows into a table with one statement? I have this: $sql2 = INSERT INTO authors (first_name, last_name, ordinal) VALUES ('$first_nameIN', '$last_nameIN', '1'); $result2 = mysql_query($sql2, $db); I want to avoid doing another insert like: $sql3 = INSERT INTO authors (first_name, last_name, ordinal) VALUES ('$first_name2IN', '$last_name2IN', '2'); $result2 = mysql_query($sql2, $db); $sql2 = INSERT INTO authors (first_name, last_name, ordinal) VALUES ('$first_nameIN', '$last_nameIN', '1'), ('$first_name2IN', '$last_name2IN', '2'); -- - michael dykman - mdyk...@gmail.com - All models are wrong. Some models are useful. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/mysql?unsub=arch...@jab.org
RE: INSERT question...
After doing an INSERT, you may do SELECT last_insert_id(); and it will return the last id the last INSERT command used. it doesn't matter if your MySQL server is very busy doing inserts, if you call 'SELECT last_insert_id()' right after the INSERT, you will get the correct value. last_insert_id() returns the last insert ID of that connection ID, so you will get the correct values. - Johnny Withers [EMAIL PROTECTED] p. 601.853.0211 c. 601.954.9133 -Original Message- From: Josh Burroughs [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 06, 2001 6:18 PM To: [EMAIL PROTECTED] Subject: INSERT question... Hi-o! I was wondering if it's possible when inserting a value into a table that has an auto_increment field to have MySQL return the value of the auto_increment field right after doing the insert, w/out having to run a seperate query? For example if I had a table with two collums, ID and name. Where ID is an int field with auto_increment set, and is the primary key. and name is just a varchar. and did this: INSERT INTO some_table (name) VALUES("bob"); I'd like for the query to return the value for ID that was just assigned. Is there a way to do this all in one SQL statement? Thanks in advance! "Listen: We are here on Earth to fart around. Don't let anybody tell you any different!" - Kurt Vonnegut Josh Burroughs [EMAIL PROTECTED] - 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 - 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