从另一个表插入Mysql查询

时间:2017-07-06 09:49:08

标签: mysql insert

当使用下面的查询时,我正在插入product_id,我还想为所有插入的product_id设置字段category_id = 4。这是我插入产品的代码。

INSERT INTO lc_products_to_categories
( product_id)
SELECT product_id
FROM lc_products_info
where name like '%awesome product%'

如何使用单个查询更新category_id?

1 个答案:

答案 0 :(得分:0)

INSERT INTO lc_products_to_categories
( product_id, category_id)
SELECT product_id, 4
FROM lc_products_info
where name like '%awesome product%'