如何从2表使用JOIN SQLite中删除数据数据、JOIN、SQLite

2023-09-06 23:07:31 作者:谢谢赠我空欢喜

我有如下表

我要删除对应的数据的 productId参数的两个表。我研究了JOIN不能与删除源码应用,所以我已经尝试下面的查询

I want to delete the data corresponding to the productId from both the tables. I have studied that JOIN can not be applied with DELETE in sqlite so i have tried the below query

DELETE FROM optionToValues WHERE optionToValues.optionId   IN
(SELECT optionToValues.optionId
FROM optionToValues 
JOIN productOptions on productOptions.optionId = optionToValues.optionId 
WHERE productOptions.product_id = 82)

但不进行任何删除操作。请给我建议的东西,我们如何能做到这一点。任何帮助是AP preciated。

But no delete operation is performed. Please suggest me something how we can achieve this. Any help is appreciated.

推荐答案

您会想这一点 -

DELETE 
  FROM optionToValues
 WHERE optionId IN ( SELECT optionId FROM productOptions WHERE product_id = 82 )

DELETE
  FROM productOptions
 WHERE product_id = 82