Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLITE - insert question

Tags:

sqlite

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.

like image 694
Ilya Suzdalnitski Avatar asked Aug 08 '26 20:08

Ilya Suzdalnitski


2 Answers

INSERT INTO table02 (item_id, status, card_status) SELECT item_id, -1, 10 FROM table01;
like image 117
Sergey Olontsev Avatar answered Aug 10 '26 13:08

Sergey Olontsev


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.

like image 34
idstam Avatar answered Aug 10 '26 15:08

idstam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!