Insert multiple rows using select

I am trying to insert 2 rows into the same table. The first will input data from a select, the second will use vars for data. I am able to insert the first row but having trouble inserting multiple rows.

The $partner_id is to link the rows to each other. For this im using a generated 32char value in php. Is there anyway to set the edit_partner_id with mysql as the id of the first row inserted or is this not possible due to the first row has to be created before you can get the last id?

Is it possible to also add an update to this or would I have to run this in a seperate query?

$sql = "INSERT INTO edits_customers (customer_id, creator_id, firstname, surname,
            house_no, address_1, address_2, address_3, city, county, postcode,
            country, email, home_tel, mobile_tel, work_tel, notes, edit_type,
            edit_partner_id )
        (SELECT *, 'before', '{$partner_id}' FROM customers WHERE = 123),
        ('{$var1}', '{$var2}', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
            '', 'after', $partner_id)";



If I'm understanding your question correctly, where you're trying to insert some data from another table and some data you provide yourself, you should be able to do something like this using UNION:

INSERT INTO SomeTable ( Col1, Col2, Col3 )
SELECT Val1, Val2, Val3 FROM SomeOtherTable
SELECT 'MyProvidedVal1', 'MyProvidedVal2', 'MyProvidedVal3'

Hope that helps...

Need Your Help

Creating a new log file each day

c# winforms logging log4net

As the title implies how can I create a new log file each day in C#? Now the program may not necessarily run all day and night but only get invoked during business hours. So I need to do two things...