MYSQL之You can't specify target table for update in FROM clause解决办法
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 from tbl b where a.tac=b.tac group by tac HAVING count()>
)
group by tac
)
改写成下面就行了:
delete from tbl where id in
(
select a.id from
(
select max(id) id from tbl a where EXISTS
(
select from tbl b where a.tac=b.tac group by tac HAVING count()>
)
group by tac
) a
)
也就是说将select出的结果再通过中间表select一遍,这样就规避了错误。注意,这个问题只出现于mysql,mssql和oracle不会出现此问题。
You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据。
例如:
我想查询t_user_asset的余额加上50000作为更新字段f_cashAmount的值,这样写是不行的。
UPDATE t_user_asset SET f_cashAmount =
(
SELECT (ua.f_cashAmount+) cashAmount FROM t_user_asset ua WHERE ua.f_userId =
)
WHERE f_userId =
修改成以下写法就行,意思就是变个方向,在select外边套一层,让数据库认为你不是查同一表的数据作为同一表的更新数据:
UPDATE t_user_asset SET f_cashAmount =
(
SELECT ub.cashAmount FROM
(
SELECT (ua.f_cashAmount+) cashAmount FROM t_user_asset ua WHERE ua.f_userId =
) ub
)
WHERE f_userId =
以上问题只针对mysql数据库
MYSQL之You can't specify target table 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错误解决方法,需要的朋友可以参考下 MySQL中You c ...
- MYSQL 1093 之You can't specify target table for update in FROM clause解决办法
You can't specify target table 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错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...
- MySQL 出现You can't specify target table for update in FROM clause错误解决方法
MySQL出现You can’t specify target table for update in FROM clause 这个错误的意思是不能在同一个sql语句中,先select同一个表的某些值 ...
- mysql error:You can't specify target table for update in FROM clause
mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表( ...
- Mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。
将select出的结果再通过中间表select一遍,这样就规避了错误.注意,这个问题只出现于mysql,mssql和oracle不会出现此问题. mysql中You can't specify tar ...
- mysql You can't specify target table for update in FROM clause解决方法
mysql You can't specify target table for update in FROM clause解决方法出现这个错误的原因是不能在同一个sql语句中,先select同一个表 ...
- mysql 出现You can't specify target table for update in FROM clause错误的解决方法
mysql出现You can’t specify target table for update in FROM clause 这个错误的意思是不能在同一个sql语句中,先select同一个表的某些值 ...
- mysql中You can't specify target table for update in FROM clause
使用mysql在删除表中重复记录 delete from user where username in (select user name form(select username from user ...
随机推荐
- RAID常见问题集锦+底部案例
磁盘阵列(Redundant Arrays of Inexpensive Disks,RAID),有“价格便宜具有冗余能力的磁盘阵列”之意.原理是利用数组方式来作磁盘组,配合数据分散排列的设计,提升数 ...
- 【转】Android的root原理
转自知乎:https://www.zhihu.com/question/21074979 @Kevin @张炬 作者:Kevin链接:https://www.zhihu.com/question/21 ...
- Android创建并响应选项菜单
创建options menu 之前提到,Android的activity已经为我们提前创建好了android.view.Menu对象,并提供了回调方法onCreateOptionsMenu(Menu ...
- [转载]CMMI之功能点估算法:EI、EQ和EO
EI.EO.EQ EI是处理来自于应用程序边界外部的一组数据的输入,它的主要目的是维护一个或多个ILF,以及/或者更改系统的行为. EO是输送数据到应用程序边界外部的过程.它的主要目的是通过逻辑处理过 ...
- xorm的sql builder
最近在使用xorm,并使用了sql builder来构建sql查询没想到升级后原来可以使用的代码居然报错了. 0x00 代码 sql, args, _ := builder.Select(" ...
- python json 数据操作
python 有专门针对 json 操作的函数 #!/usr/bin/python3 import json mytest_js = { "a" : 1, "b" ...
- [cpu]TI cortex-A9 查看cpu的频率
Hi Aaron, For checking and changing Cortex-A9 CPU frequency in u-boot, refer to the below files: u-b ...
- if语句和switch语句
1.基本写法 if if(逻辑表达式){语句:}else if{语句:else{语句:} switch switch(变量){case 常量值:语句:break:default:语句:} 2.举例 i ...
- Centos7下Yum安装PHP5.5,5.6,7.0
默认的版本太低了,手动安装有一些麻烦,想采用Yum安装的可以使用下面的方案: 1.检查当前安装的PHP包 yum list installed | grep php 如果有安装的PHP包,先删除他们 ...
- Windows下超强日志工具BareTail
最近写了一些测试工具,经常希望能动态的查看日志文件,试了好些文本编辑文件如Emeditor.Vim等,一直没找到合适. 我希望支持的功能有: 支持大文件读取,速度要快 自动加载新的内容,直接定位到最后 ...