INSERT INTO campaign_ledger (`campaign_id`, `description`, amount, balance, timestamp)
VALUES (SELECT id as campaign_id, 'Ported from campaigns' as description, budget_remaining as amount, budget_remaining as balance, NOW() as timestamp FROM campaigns)
That’s my syntax, but I get an error saying:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘SELECT id as campaign_id, ‘Ported from campaigns’ as
description, budget_remaini’ at line 2
What am I doing wrong?
Since you are selecting from a table then you will want to use an
INSERT INTO SELECT FROMquery:Only use
INSERT INTO VALUESwhen you are using specific values and not selecting from a table. If you wanted to useINSERT INTO VALUESthen your query would be like this: