在我的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)
你能報告錯誤嗎? –
沒有錯誤,只是一個空的結果。 –