3

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

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?

4

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.

于 2012-12-03T09:09:26.643 回答