MySQL [Err] 1093 - You can't specify target table 'test' for update in FROM clause
2017-08-02 12:30
645 查看
今天在群里面看见以为大兄弟提出这么一个问题:
这句SQL会报错,但是如果把select id from test写成常量、死数据,那么这条SQL就能正确的执行。究其原因,问题出在哪里呢。仔细查看提示信息,我们发现,这个提示信息告诉我们的是:我们不能在同一条语句中先select出同一表中的某些值,再update这个表,这个操作在MySQL中是被禁止的。那我们如何修改这条SQL呢?改成下面这条SQL就行
我们做一个子查询,规避一下这个问题,就不会被MySQL认定我们是在操作同一张表。当然这个问题只出现在MySQL中,Oracle中是不会出现这样的错误的。
delete from test where id in (select id from test)
这句SQL会报错,但是如果把select id from test写成常量、死数据,那么这条SQL就能正确的执行。究其原因,问题出在哪里呢。仔细查看提示信息,我们发现,这个提示信息告诉我们的是:我们不能在同一条语句中先select出同一表中的某些值,再update这个表,这个操作在MySQL中是被禁止的。那我们如何修改这条SQL呢?改成下面这条SQL就行
delete from test where id in (select a.id from( 4000 select id from test)a)
我们做一个子查询,规避一下这个问题,就不会被MySQL认定我们是在操作同一张表。当然这个问题只出现在MySQL中,Oracle中是不会出现这样的错误的。
相关文章推荐
- [Err] 1093 - You can't specify target table 'table' for update in FROM clause处理
- mysql错误:1093-You can’t specify target table for update in FROM clause的解决方法
- mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法
- MySQL 错误码: 1093 You can't specify target table 'jc_user' for update in FROM clause
- MySQL数据库update更新子查询[Err] 1093 - You can't specify target table 'text' for update in FROM clause
- mysql Error Code: 1093. You can't specify target table 'base_extend' for update in FROM clause 0.001
- Mysql 错误 Code: 1093. You can't specify target table for update in FROM clause
- [Err] 1093 - You can't specify target table 'matorder' for update in FROM clause 原句:delete from mat
- [Err] 1093 - You can't specify target table 's' for update in FROM clause
- MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause
- mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法
- [Err] 1093 - You can't specify target table 's' for update in FROM clause
- [Err] 1093 - You can't specify target table 'ExtraPrivilege' for update in FROM clause
- [Err] 1093 - You can't specify target table 'image' for update in FROM clause
- [Err] 1093 - You can't specify target table 'exam_arrange_list' for update in FROM clause
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- MySQL 中 You can't specify target table '表名' for update in FROM clause错误解决办法
- [Django](1093, "You can't specify target table 'fee_details_invoices' for update in FROM clause") 错误
- mysql中You can't specify target table for update in FROM clause错误
- MySQL报错“ you can't specify the target table for ‘update’ in from clause”