程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> MYSQL delete語句不支持別名的問題

MYSQL delete語句不支持別名的問題

編輯:MySQL綜合教程


有一個表的數據比較大,然後需要進行關聯刪除,刪除的時候發現如下SQL報錯:   DELETE FROM test.test1 a WHERE EXISTS (SELECT 1 FROM test.test2 b WHERE a.recordID=b.smsInfoID AND b.receiveTime <="2011-10-09 00:00:00" ) limit 1000;
  報錯如下:   Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a WHERE EXISTS (SELECT 1 FROM test.test2 b WHERE a.recordID=b.smsInf' at line 1  www.2cto.com   開始以為是exists的問題,於是更改成in再測試,也報同樣錯:   DELETE FROM test.test1 a WHERE a.recordid IN (SELECT b.smsInfoID FROM test.test2 b WHERE b.receiveTime <= "2011-10-09 00:00:00") LIMIT 1000;   原來是MYSQL的delete語句不支持別名!   將別名去掉就可以了,將上面兩個報錯的SQL更改成如下形式就可以了:   DELETE FROM test.test1 WHERE recordid IN (SELECT smsInfoID FROM test.test2 WHERE receiveTime <= "2011-10-09 00:00:00") LIMIT 1000;  www.2cto.com   DELETE FROM test.test1 WHERE EXISTS (SELECT 1 FROM test.test2 WHERE test1.recordID=test2.smsInfoID AND test2.receiveTime <= "2011-10-09 00:00:00") LIMIT 1000;       作者 飛鴻無痕

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved