2011-01-09 108 views
0

我挣扎,我的选择查询转换为一个更新查询,它的别名..我该如何解决这个错误?您不能指定目标表我的表更新在FROM子句

Update pads set RemoveMeDate = '1999-01-01 00:00:00' where padid in (
SELECT old_table.padid 
FROM `jules-fix-reasons`.`pads` AS old_table 
JOIN `jules`.`pads` AS new_table ON old_table.padid = new_table.`PadID` 
WHERE new_table.RemoveMeDate <> '2001-01-01 00:00:00' 
AND old_table.RemoveMeDate = '2001-01-01 00:00:00') 

我试图消除别名,但是,这并不利于:(

编辑 - 理查德,屏幕截图 alt text

+0

看看http://www.xaprb.com/blog/2006/06/23/how-to- select-from-an-update-target-in-mysql/ – 2011-01-09 09:25:02

+0

是的,我看到了它不适用于我 – Jules 2011-01-09 09:30:52

回答

0
Update pads 
set RemoveMeDate = '1999-01-01 00:00:00' 
where padid in (SELECT padid FROM 
       (SELECT old_table.padid 
       FROM `jules-fix-reasons`.`pads` AS old_table JOIN 
         `jules`.`pads` AS new_table ON old_table.padid = new_table.PadID 
       WHERE new_table.RemoveMeDate <> '2001-01-01 00:00:00' AND old_table.RemoveMeDate = '2001-01-01 00:00:00') a)