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 1093 You canMySqlError
- MYSQL SOURCE報錯 ERROR: ASCIIMySqlErrorASCII
- MySQL報錯 Error_code: 1045MySqlError
- Mysql報錯Fatal error:Can't open and lock privilege tablesMySqlError
- 關於MYSQL DML(UPDATE DELETE)中的子查詢問題和ERROR 1093 (HY000)錯誤MySqldeleteError
- MySQL error 錯 誤 碼MySqlError
- vipca報錯 Error 0PCAError
- Mysql update in報錯 [Err] 1093 - You can't specify target table 'company_info' for update in FROM clauseMySql
- Mysql資料庫報ERROR 1045 (28000)報錯及MySQL忘記密碼找回MySql資料庫Error密碼
- ERROR 1045 (28000): ProxySQL Error: 報錯ErrorSQL
- MySQL 5.7.17 安裝報錯SSL error: Unable to get private key fromMySqlError
- MySQL 5.5 原始碼安裝報錯"[ERROR] Can't start server"MySql原始碼ErrorServer
- MySQL 5.6複製報錯Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND;MySqlError
- oracle和mysql關於關聯更新的一些差別以及ERROR 1093OracleMySqlError
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- MySQL 啟動報錯 error while loading shared librariesMySqlErrorWhile
- 【Redis】slaveof 報錯 Background transfer errorRedisError
- Oracle安裝報錯syntax errorOracleError
- struts2報Error filterStart錯ErrorFilter
- 網站報錯:“Database Server Error”網站DatabaseServerError
- MySQL報錯ERROR 2013 (HY000): Lost connection to MySQL server during queryMySqlErrorServer
- MySQL5.6:mysql_secure_installation 報錯ERROR 2002 (HY000)MySqlError
- mysql登入報錯提示:ERROR 1045 (28000)的解決方法MySqlError
- MySQL8.0.28命中[ERROR][MY-013183]報錯案例分析MySqlError
- mysql執行sql指令碼報錯ERROR 1366 (HY000) 解決MySql指令碼Error
- MySQL 5.7 多主複製報錯Coordinator stopped because there were error(s)MySqlError
- MySQL 5.7.17 安裝報錯CMake Error at cmake/boost.cmake:81 (MESSAGE)MySqlError
- MySQL 5.5 報錯"ERROR 1075 (42000): Incorrect table definition"MySqlError
- MySQL報錯'ERROR 2002 (HY000): Can't connect to local MySQL server through'MySqlErrorServer
- 一看便知linux下mysql報錯ERROR 1044: Access denied for user: '@localhost' to database 'mysql'LinuxMySqlErrorlocalhostDatabase
- 【MySQL】老版本mysql奇怪的報錯:ERROR 1046 (3D000): No database selected(BUG)MySqlError3DDatabase
- MySQL ERROR 1698 (28000) 錯誤MySqlError
- Ubuntu 系統 apt 報錯:relocation errorUbuntuAPTError
- pip install scrapy報錯:error: UnableError
- 反序列 unserialize(): Error 報錯問題Error
- 【MySQL】ERROR 1290 (HY000): --secure-file-priv--匯出報錯MySqlError
- mysql 5.6.25報錯ERROR 1372 (HY000): Password hash 的一點思考MySqlError
- MySQL 報錯 ERROR 1290 (HY000): running with the --secure-file-privMySqlError