I've got a list of items in a certain table and I want to have another table with an ID from the first table and another constant values in other columns.
I've got the following query:
INSERT INTO table02(item_id, status, card_status) VALUES( (SELECT item_id FROM table01), -1, 10);
But it works only for the first row.
How can I make it work for all rows? I need to copy all IDs from table01 and assign to them values -1 and 10 in other columns.
Thanks.
INSERT INTO table02 (item_id, status, card_status) SELECT item_id, -1, 10 FROM table01;
In ANSI SQL it would be:
INSERT INTO table02(item_id, status, card_status)
SELECT item_id, status, card_status FROM table01;
where status and card_status are your hard coded values.
...so I guess that would work here too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With