我有一个令人困惑的问题。我的查询是这样的;
insert into simple_products
(Product_Id,attribute,quantity,Barcode)
values ((select id from products where sku='180 JK101G' and attribute='4621'),26,2,1068215)
ON DUPLICATE KEY UPDATE
attribute=values(attribute),
quantity=values(quantity),
Barcode=values(Barcode)
但有时子查询什么都不返回。所以我想做什么,但我找不到任何解决方案。
有没有办法呢?
答案 0 :(得分:0)
您正在寻找insert ... select
insert
into simple_products (Product_Id, attribute, quantity, Barcode)
select id, 26, 2, 1068215
from products
where sku='180 JK101G'
and attribute='4621'
on duplicate key update
attribute=values(attribute),
quantity=values(quantity),
Barcode=values(Barcode);
答案 1 :(得分:0)
感谢@IvanM
解决了这个问题 insert into simple_products (Product_Id,attribute,quantity,Barcode)
select id,26 as a,2 as b ,1068215 as c from products where sku='180 JK101G' and attribute='4621'
ON DUPLICATE KEY UPDATE attribute=values(attribute), quantity=values(quantity), Barcode=values(Barcode)