2017-07-06 52 views
0

當使用下面的查詢時,我插入了product_id,並且還希望爲所有插入的product_id設置字段category_id = 4。這是我的代碼插入產品。從另一個表中插入Mysql查詢

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

如何使用單個查詢更新category_id?

+0

只是選擇這樣NSERT INTO lc_products_to_categories (產品,CATEGORY_ID)PRODUCT_ID,4 FROM lc_products_info 恆定其中name LIKE '%真棒產物%' – JYoThI

回答

0
INSERT INTO lc_products_to_categories 
(product_id, category_id) 
SELECT product_id, 4 
FROM lc_products_info 
where name like '%awesome product%' 
相關問題