mysql中You can’t specify target table for update in FROM cl
mysql中You can't specify target table for update in FROM clause錯誤的意思是說,不能先select出同一表中的某些值,再update這個表(在同一語句中)。 例如下面這個sql:
程式碼如下:
delete from tbl where id in
(
select max(id) from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
)
group by tac
)
改寫成下面就行了:
程式碼如下:
delete from tbl where id in
(
select a.id from
(
select max(id) id from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
)
group by tac
) a
)
也就是說將select出的結果再透過中間表select一遍,這樣就規避了錯誤。注意,這個問題只出現於mysql, mssql和oracle不會出現此問題。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69994010/viewspace-2753481/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- You can‘t specify target table ‘Person‘ for update in FROM clause
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- Table is specified twice, both as a target for 'UPDATE' and as a separate source
- MYSQL報1022錯誤:Can't write;duplicate key in table '.....'MySql
- Mongoose can't update timestampGo
- FILESTREAM feature can't be enabled if you use cluster shared volumes
- MySQL 2003 - Can’t connect to MySQL server on (10060)MySqlServer
- 完美解決stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.ErrorPython
- 關於 mysql 中的 select * from table_a,table_b 的問題MySql
- why you can be in netherland
- mysql遇到Variable can’t be set to the value of ‘NULL’MySqlNull
- The connection to the server 10.10.0.2:6443 was refused - did you specify the right host or port?Server
- Mysql:Variable 'XXXt' can't be set to the value of 'NULL'解決MySqlNull
- 阿里雲 Redis 報出You can't read against a non-read redis.解決方案阿里RedisAI
- Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock錯誤MySqlServer
- You don't know CSSCSS
- [leetcode] 1642. Furthest Building You Can ReachLeetCodeUI
- In the meantime you can read the IGN analysis of Madden 22
- LeetCode之All Paths From Source to Target(Kotlin)LeetCodeKotlin
- mysql 啟動報錯Can't connect to local MySQL server through socket '/data/mysql/mysql/mysql.sock'(111)MySqlServer
- You don't know css(2)CSS
- SAP MM The Table MBEWH Update Logic
- TypeError: can‘t concat str to bytesError
- Can't open file: (errno: 24)
- Can't Connect to MySQL Server on IP Address (10061) 錯誤的解決方案MySqlServer
- Extract rows from a CORRUPT table creating ROWID from DBA_EXTENTS
- [LeetCode] 1953. Maximum Number of Weeks for Which You Can WorkLeetCode
- Composer 建立專案 You can also run `PHP --INI`PHP
- S2 - Lesson 57 - Can I help you, madam?
- Incorrect MEMORY_MAX_TARGET (> Available RAM) Can Lead To Database HangsAIDatabase
- Supervisor 解決 can't find command *
- SSM+Swagger問題解決 Can‘t read swagger JSON from http://localhost:8080/xxx/swagger/api-docsSSMSwaggerJSONHTTPlocalhostAPI
- mysqld: Can‘t create directory ‘E:\Software\mysql-5.7.24-winx64\data\‘ (Errcode: 2 - NoMySql
- eslint --fix 報錯 can't not find modulesEsLint
- Can't load IA 32-bit .dll on a
- multiprocessing pool AttributeError: Can't get attribute 'func'Error
- 網站提示:You Don’t Have Permission To Access網站
- 關於Warning: setState(...): Can only update a mounted or mounting component. This