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 ...
随机推荐
- Python爬虫设置Headers
Python设置Headers import urllib import urllib2 url = 'http://www.server.com/login' user_agent = 'Mozil ...
- idea linux 启动权限不足的问题
修改 ideaproject 下所有文件 chmod -R 777 文件 递归修改文件权限
- python dataframe astype 字段类型转换
使用dtype查看dataframe字段类型 print df.dtypes 使用astype实现dataframe字段类型转换 # -*- coding: UTF-8 -*- import pand ...
- Web通信
客户在浏览器输入一个有效的url地址开始,浏览器会利用socket向url对应的web服务器发送一个TCP请求,这个请求成功一次就需要来回握三次手才能确定,成功以后,浏览器利用socket TCP连接 ...
- ASP.NET学习笔记(2)——用户增删改查
说明(2017-7-4 11:48:50): 1. index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition ...
- redis主从配置(docker实现)
一.docker新建两个redis服务端,并分别设置端口为6379和6380 命令如下: docker run -p : -d --name redis-server docker.io/redis: ...
- Google工作原理
网上看到一张讲解Google工作原理的图,与大家分享一下:
- 创建function实现hive表结果导出到mysql
1. 创建临时function (这里两个包都是hive自带的,不需要自己开发的,可以根据名称查找对应的版本) add jar /opt/local/hive/lib/hive-contrib-.ja ...
- [转]Java动态代理
动态代理在Java中有着广泛的应用,比如Spring AOP,Hibernate数据查询.测试框架的后端mock.RPC,Java注解对象获取等.静态代理的代理关系在编译时就确定了,而动态代理的代理关 ...
- Nexus 7更换NFC控制器,导致不再支持读取Mifare Classic NFC 1k Tags
In a review conducted by Anandtech, it was found that the Nexus 4 makes use of the Broadcom BCM20793 ...