mysql報錯ERROR 1093
今天在嘗試用子查詢來關聯更新一個表的收到如下報錯:
ERROR 1093 (HY000): You can't specify target table 'v_member_info' for update in FROM clause
具體執行的sql如下:
MySQL [meminfo]> update v_member_info set cust_right_group=0 where id in (select id from v_member_info where pay_end_date<'2018-01-29' and cust_right_group>0);
ERROR 1093 (HY000): You can't specify target table 'v_member_info' for update in FROM clause
原來是mysql在update的時候, 原始表不能出現在where 後面第一層的子查詢中;
解決辦法:兩種改寫方法
1)改寫成join方式更新
MySQL [meminfo]> update v_member_info as a ,(select id,cust_right_group from v_member_info where pay_end_date<'2018-01-29' and cust_right_group>0) as b set a.cust_right_group=0 where a.id=b.id;
Query OK, 288 rows affected (2.35 sec)
Rows matched: 288 Changed: 288 Warnings: 0
2)或者改成子查詢之子查詢
MySQL [meminfo]> update v_member_info set cust_right_group=0 where id in(select id from (select id from v_member_info where pay_end_date<'2018-01-29' and cust_right_group>0)a);
小結:Oracle和MySQL還是有區別的,MySQL在update的時候,原始表不能出現在where 後面第一層的子查詢當中,至於兩種改寫的效能的看具體業務和資料量的大小。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29654823/viewspace-2151383/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 啟動報錯 error while loading shared librariesMySqlErrorWhile
- MySQL error 錯 誤 碼MySqlError
- MySQL建立觸發器時報錯Error Code: 1064MySql觸發器Error
- ERROR 1045 (28000): ProxySQL Error: 報錯ErrorSQL
- MySQL報錯ERROR 2013 (HY000): Lost connection to MySQL server during queryMySqlErrorServer
- Mysql資料庫報ERROR 1045 (28000)報錯及MySQL忘記密碼找回MySql資料庫Error密碼
- mysql匯入sql檔案報錯 ERROR 2013 2006 2002MySqlError
- MySQL8.0.28命中[ERROR][MY-013183]報錯案例分析MySqlError
- MySQL 5.6複製報錯Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND;MySqlError
- MySQL 報錯 ERROR 1290 (HY000): running with the --secure-file-privMySqlError
- mysql登入報錯提示:ERROR 1045 (28000)的解決方法MySqlError
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- MYSQL5.7.22全庫備份匯入MYSQL8.0.20報錯ERROR3554MySqlError
- 【MySQL】ERROR 1290 (HY000): --secure-file-priv--匯出報錯MySqlError
- 【Redis】slaveof 報錯 Background transfer errorRedisError
- 網站報錯:“Database Server Error”網站DatabaseServerError
- pip install scrapy報錯:error: UnableError
- mysql 5.6.25報錯ERROR 1372 (HY000): Password hash 的一點思考MySqlError
- MySQL主從同步報error 1236MySql主從同步Error
- MySQL 5.7 建立使用者報錯 ERROR 1805 (HY000): Column count of mysql.user is wrongMySqlError
- mysql 索引長度 767 錯誤 ERROR 1071MySql索引Error
- Centos7-mysql執行報錯ERROR1820(HY000):YoumustresetyourpasswordusingALTERUSERstatementbeforeexecutingthisstatement.CentOSMySqlError
- MySQL 5.7初始化報錯error while loading shared libraries: libnuma.so.1MySqlErrorWhile
- Ubuntu 系統 apt 報錯:relocation errorUbuntuAPTError
- weblogic報錯: OPatch failed with error code 73WebAIError
- ogg報錯error 11, Resource temporarily unavailableErrorAI
- 反序列 unserialize(): Error 報錯問題Error
- Mysql連線錯誤ERROR 2003 (HY000)MySqlError
- 2、MySQL錯誤日誌(Error Log)詳解MySqlError
- DZ論壇MySQL Query Error Errno:1046錯誤MySqlError
- Mysql啟動報錯:Job for mysqld.service failed because the control process exited with error code.MySqlAIError
- MySQL主從複製報錯:Got fatal error 1236 from master when reading data fromMySqlGoErrorAST
- MySQL建立使用者報錯 ERROR 1396 (HY000): Operation CREATE USER failed for 'afei'@'%'MySqlErrorAI
- MySQL 5.7從庫報錯exceeds of slave_pending_jobs_size_max. Error_code: 1864MySqlError
- Oracle dataguard報錯:Error 1017 received logging on to the standbyOracleError
- linux系統報錯AER PCIe Bus ErrorLinuxError
- 執行flutter run命令報錯::ERROR: Could not connect to lockdownd, error code -17FlutterError
- mysql 8 報錯 ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repositoryMySqlErrorAIStruct
- mysql 啟動錯誤(InnoDB: Operating system error number 13 )MySqlError