[英]SQL How to Delete Data from Table Using INNER JOIN
I'm trying to delete all records form the table "oc_products" that don't have a certain category ID. 我正在尝试删除表格“ oc_products”中没有特定类别ID的所有记录。 I created a SELECT query that lists those products using an INNER JOIN, since the categories are in a separate table. 我创建了一个SELECT查询,该查询使用INNER JOIN列出了这些产品,因为类别在单独的表中。
What I can't figure out is how to use the DELETE function to delete the shown records. 我不知道如何使用DELETE函数删除显示的记录。
This is what my code looks like: 这是我的代码如下所示:
DELETE oc_product
FROM oc_product
INNER JOIN oc_product_to_category ON oc_product.product_id = oc_product_to_category.product_id
WHERE oc_product_to_category.category_id = 343
Its showing the error "Unexpected keyword, (near INNER JOIN)". 其显示错误“意外的关键字,(INNER JOIN附近)”。
Add .* to p in your first line. 在第一行中将。*添加到p。
Try: 尝试:
DELETE p.* FROM oc_product p
INNER JOIN oc_product_to_category pc ON p.product_id =
pc.product_id
WHERE pc.category_id = 343
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.