Since you are selecting from a table, you need to use the INSERT INTO SELECT FROM
query:
INSERT INTO campaign_ledger ( `campaign_id` , `description` , amount , balance , timestamp ) SELECT id as campaign_id , 'Ported from campaigns' as description , budget_remaining as amount , budget_remaining as balance , NOW() as timestamp FROM campaigns
Use only INSERT INTO VALUES
when you are using certain values ββand not selecting from a table. If you want to use INSERT INTO VALUES
, then your query will look like this:
INSERT INTO campaign_ledger ( `campaign_id` , `description` , amount , balance , timestamp ) VALUES ( 1 , 'test' , 100.00 , 1000.00 , NOW() )
Taryn source share