我的首選語法是:
Delete deleteAlias
/* Select * */
from table1 deleteAlias
where exists (select null from table1 innerTable1 INNER JOIN table2 ON table2.user = innerTable1.uid
INNER JOIN table3 ON table3.uid = table2.seminar WHERE table3.end_date < CURDATE())
AND deleteAlias.uid = innerTable1.uid
)
如果這種方法是微妙的好處,您可以用一個簡單的「select *」來替換運行刪除之前將刪除的內容。
/* Delete deleteAlias */
Select *
from table1 deleteAlias
where exists (select null from table1 innerTable1 INNER JOIN table2 ON table2.user = innerTable1.uid
INNER JOIN table3 ON table3.uid = table2.seminar WHERE table3.end_date < CURDATE())
AND deleteAlias.uid = innerTable1.uid
)
標識表1似乎是ambigious,因爲你在你的外部查詢('DELETE')使用它,以及在內部查詢,你需要給它一個別名在內部查詢中,並在您的條件下使用它來使其工作 – DrCopyPaste