Можете да направите inner join
на таблицата на продуктите и състоянието с помощта на FK product_id
и филтрирайте order_status_id
в клаузата where.
Delete t
from TablenName t join
(select op.product_id, sum(op.quantity) as quantity
from oc_order_product op
inner join oc_order_status os on os.product_id =op.product_id
where os.order_status_id IN (3,5,17,19,20,23,25,26,29)
group by op.product_id
) op
on op.product_id = t.product_id and op.quantity < 2;