I have a database holding some default data depending on a variable. I want to create a query which copies the default data in to another table as well as insert some other data
eg.
INSERT table_1 (id, value1, value2)
SELECT value1, value2 FROM table_2 WHERE group = ‘1’,id=2
Is it possible in one statement? Or will I have to do this as two statements?
INSERT table_1 (id, value1, value2)
SELECT
2
, value1
, value2
FROM table_2
WHERE group = '1'
I am creating a new entry, which gives me a new id
I then want to create a second entry with the same id, but with data from another table.
I will have the id saved as a variable in my php script, so it could just come from that
Yes. But what are you trying there in your example? Why is there a comma and then “id=2” ? Is that part of the WHERE clause? It should be WHERE group=‘1’ AND Id=2
But let me get this straight… You want to INSERT data from a table_2 into another table_1, but also want to INSERT data from another source into table_1 too. Right?
Where is this other data coming from?