Reputation: 17
I have a confusing problem. My query like this;
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)
But sometimes subquery returns nothing. So I want then do nothing but I can't find any solution.
Is there a way for this?
Upvotes: 0
Views: 378
Reputation: 17
It's solved thanks to @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)
Upvotes: 0
Reputation: 39981
You are looking for 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);
Upvotes: 1