我正在升级和优化旧的表结构。
为了正确使用replace into
,我删除了干扰2列新唯一键的旧僵尸条目。
查询:
DELETE from `relProductsPrices` where `ID` in
(SELECT scanA.ID from `relProductsPrices` as scanA
inner join `relProductsPrices` as scanB
where scanA.ID < scanB.ID
and scanA.product = scanB.product
and scanA.priceName = scanB.priceName);
错误:
#1093 - You can't specify target table 'relProductsPrices' for update in FROM clause
我现在还不确定如何正确地将其合并到一个mySQL查询中?
我希望这个问题没有重复的条目,我似乎无法找到类似的,适应性的条目。有关于此错误的问题,但我在这里根本没有更新查询,大多数人所说的解决方案(创建一个子选择)已经事先由我完成了。
提前致谢!
答案 0 :(得分:10)
试试这个:
DELETE FROM `relProductsPrices`
WHERE `ID` IN (
SELECT
tmp.ID
FROM (
SELECT
scanA.ID
FROM
`relProductsPrices` as scanA
INNER JOIN `relProductsPrices` as scanB
ON scanA.ID < scanB.ID
AND scanA.product = scanB.product
AND scanA.priceName = scanB.priceName
) as tmp
);