在我的Opencart商店中,我有许多产品可以选择颜色和尺寸。 有时由于从excel导入,颜色选项只有一个值,例如白色。当依赖关系的价值基础上移除两个表中的记录
我想远程所有选项,其中optionvalue只有一个选择。
该信息存储在两个表中:oc_product_option_value
和oc_product_option
。
例如在oc_product_option_value这看起来是这样的:
product_id option_id
--------------------
66 18
66 18
66 17
67 18
67 18
67 17
所以我想需要与选项17
除去一次66选17和一次67当我使用:
select * from oc_product_option_value group by product_id, option_id having count(*) = 1
它给我所有的product_id只有一个optionvalue,我可以删除它。 但我还需要从表oc_product_option删除相同的product_id。 如何选择oc_product_option中只有oc_product_option_value中有一个选项值的所有产品。
我试过,但它不工作:
select * from oc_product_option
where option_id IN (select product_id from oc_product_option_value group by product_id, option_id having count(*) = 1)
你能报告错误吗? –
没有错误,只是一个空的结果。 –