I have this SQL query :
INSERT INTO db1.outbox (DestinationNumber, TextDecoded)
SELECT User.CellPhone, '$SMSMessage' as TextDecoded
FROM db2.User
WHERE User.PurchaseDate BETWEEN 2012-01-01 AND 2012-01-31
it does multiple rows insertion to ‘outbox’ table. and I can easily get the ID number of first row by using this query :
SELECT LAST_INSERT_ID()
and let’s say I have 532 as result from SELECT LAST_INSERT_ID() and I have 34 rows inserted.
how to use this 532 as initial number for other table named ‘outbox_multipart’ insertion and having it auto increment so the result will be like this :
+------+----------------+----------+----------------------------------+
| ID | phonenumber | outboxID | message |
+------+----------------+---------------------------------------------+
| ...... |
| 1025 | 555-123456 | 532 | part 2 : hello there! |
| 1026 | 555-999999 | 533 | part 2 : hello there! |
| 1027 | 555-888888 | 534 | part 2 : hello there! |
| |
| ...... 34 rows inserted here ....... |
| |
+------+----------------+---------------------------------------------+
please note that outboxID column isn’t auto increment column. but it must have auto increment number from 532 + 34 rows = 566.
Try with this
it will increments from the 532,
and remember that the “outboxID” should also be in auto increment initially