I've seen this with almost the same problems as me MySQL INSERT IF (custom if statements).
but I did not successfully execute this query:
INSERT into cart_items (product_id,product_variant_id,product_attribute_id,cart_id,quantity)
select (7,7,12,11,4)
where (select pa.stock from product_attribute as pa where pa.id = 12) > 4
in this case this is (7,7,12,11,4) value of this (product_id,product_variant_id,product_attribute_id,cart_id,quantity)
product_id: 7
product_variant_id :7
product_attribute_id : 12
cart_id : 11
quantity : 4
in my headiSQL i got error like this :
SQL (Error(1241) : Operand should contain 1 column(s)
Table cart_items
ID : Primary key autoincrement
product_variant_id : Foreign key
product_attribute_id : Foreign key
product_id : Foreign key
cart_id : Foreign key
quantity :int
Table product_attribute
ID : Primary key autoincrement
product_id : Foreign key
product_variant_id :Foreign key
size : varchar
stock : int
I want to make query if cart_items quantity less than product_attribute stock than insert