我写的这个查询SELECT sql,我需要实际删除它在输出中提供的所有数据,只是因为我无法在DELETE sql查询中正确转换它而不会遇到语法错误。
这里是查询:
SELECT *
FROM ps_attribute_impact AS at
LEFT JOIN
ps_product_attribute AS prod_at
ON at.id_product = prod_at.id_product
LEFT JOIN
ps_product_attribute_combination AS comb
ON prod_at.id_product_attribute = comb.id_product_attribute
WHERE comb.id_attribute='1' AND at.price='0.00' AND at.id_attribute='1' AND prod_at.price='0.00'
我已经尝试了这3个查询:
DELETE *
FROM ps_attribute_impact AS at
LEFT JOIN
ps_product_attribute AS prod_at
ON at.id_product = prod_at.id_product
LEFT JOIN
ps_product_attribute_combination AS comb
ON prod_at.id_product_attribute = comb.id_product_attribute
WHERE comb.id_attribute='1' AND at.price='0.00' AND at.id_attribute='1' AND prod_at.price='0.00'
和
DELETE ps_attribute_impact.*
FROM ps_attribute_impact AS at
LEFT JOIN
ps_product_attribute AS prod_at
ON at.id_product = prod_at.id_product
LEFT JOIN
ps_product_attribute_combination AS comb
ON prod_at.id_product_attribute = comb.id_product_attribute
WHERE comb.id_attribute='1' AND at.price='0.00' AND at.id_attribute='1' AND prod_at.price='0.00'
和
DELETE
FROM ps_attribute_impact AS at
LEFT JOIN
ps_product_attribute AS prod_at
ON at.id_product = prod_at.id_product
LEFT JOIN
ps_product_attribute_combination AS comb
ON prod_at.id_product_attribute = comb.id_product_attribute
WHERE comb.id_attribute='1' AND at.price='0.00' AND at.id_attribute='1' AND prod_at.price='0.00'
但我没有取得任何成功。 任何人都可以帮助我吗?
答案 0 :(得分:0)
multi table delete的正确语法是这样的
DELETE ps_attribute_impact
FROM ps_attribute_impact AS at
LEFT JOIN ps_product_attribute AS prod_at
ON at.id_product = prod_at.id_product
LEFT JOIN ps_product_attribute_combination AS comb
ON prod_at.id_product_attribute = comb.id_product_attribute
WHERE comb.id_attribute='1'
AND at.price='0.00'
AND at.id_attribute='1'
AND prod_at.price='0.00'
答案 1 :(得分:0)
我不确定查询的逻辑,但join
中delete
的语法是:
DELETE at
FROM ps_attribute_impact at LEFT JOIN
ps_product_attribute prod_at
ON at.id_product = prod_at.id_product LEFT JOIN
ps_product_attribute_combination comb
ON prod_at.id_product_attribute = comb.id_product_attribute
WHERE comb.id_attribute='1' AND at.price = '0.00' AND at.id_attribute = '1' AND
prod_at.price = '0.00';
因为您对where
子句中的所有表进行了比较,所以left join
实际上正在进行inner join
。为清楚起见,您应将其更改为inner join
。