从表a插入多个id到表b中。

时间:2022-04-30 22:05:21

I want to select all ids from an existing table and insert them into a newly created table, in this sort of fashion:

我想从现有的表中选择所有id,并将它们插入到新创建的表中,以这种方式:

INSERT INTO product_extend (product_id) VALUES (SELECT product_id FROM products)

Creating one new row per id. Can anyone show me how to do this?

每个id创建一个新行。谁能告诉我怎么做?

1 个解决方案

#1


3  

Like this:

是这样的:

INSERT INTO product_extend (product_id) 
SELECT product_id FROM products;

As explained in INSERT INTO ... SELECT ... in MySQL Manual.

正如插入到…选择……在MySQL手册。

#1


3  

Like this:

是这样的:

INSERT INTO product_extend (product_id) 
SELECT product_id FROM products;

As explained in INSERT INTO ... SELECT ... in MySQL Manual.

正如插入到…选择……在MySQL手册。