2011-01-09 115 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)