5

我正在升级和优化旧表结构。为了正确使用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 查询中?

我希望这个问题没有重复条目,我似乎找不到类似的,适应性强的条目。关于这个错误有一些问题,但我这里根本没有更新查询,大多数人说的解决方案(创建子选择)已经由我事先完成。

提前致谢!

4

1 回答 1

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
 );
于 2013-06-10T20:46:54.673 回答