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解决办法的更多相关文章

  1. 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 ...

  2. MYSQL 1093 之You can't specify target table for update in FROM clause解决办法

    You can't specify target table for update in FROM clause含义:不能在同一表中查询的数据作为同一表的更新数据. 出现以上错误,是因为想将表自身的字 ...

  3. 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这个表( ...

  4. 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同一个表的某些值 ...

  5. 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这个表( ...

  6. 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 ...

  7. 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同一个表 ...

  8. 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同一个表的某些值 ...

  9. 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 ...

随机推荐

  1. replace()的使用方法

    replace() 方法用于在字符串中用一些字符替换另一些字符,或替换一个与正则表达式匹配的子串. 数字类型的必须转换成字符串才能使用replace,否则会报错

  2. LeetCode:Sqrt(x) 解题报告

    Sqrt(x) Implement int sqrt(int x). Compute and return the square root of x. SOLUTION 1: 参见:二分法总结,以及模 ...

  3. S3C2440时钟体系结构

    任意一款单板,我们了解其时钟都是通过时钟树来的. 这里没有全部截完,只是讲解时钟来源,OSC代表晶振,这说明我们的时钟可以来至晶振OSC也可以来至外部输入EXTCLK,这是通过OM选择器来完成的. 2 ...

  4. 网络构建入门技术(3)——IP地址分类

    说明(2017-5-16 09:48:08): 1. IP地址

  5. Eigen教程(5)

    整理下Eigen库的教程,参考:http://eigen.tuxfamily.org/dox/index.html 块操作 块是matrix或array中的矩形子部分. 使用块 函数.block(), ...

  6. 基于jQuery图片自适应排列显示代码

    基于jQuery图片自适应排列显示代码.这是一款基于jquery.flex-images插件实现的类似谷歌图片流效果.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div ...

  7. bash里wget失败

    直接使用wget是可以的,然而在shell脚本里却不行,后来发现原来是换行符的问题,编辑器默认的是\r\n,一不留神,自己把自己坑了

  8. JedisConnectionPool scala

    /** * Created by lq on 2017/8/29. */ object JedisConnectionPool { val config = new JedisPoolConfig() ...

  9. TP v5中环境变量在项目中的应用

    环境变量,顾名思义就是在不同的系统环境,同一个变量的值可以有所不同. 如开发环境.测试环境与正式环境下,数据库配置.静态资源文件Url前缀.缓存.各种key等配置都不相同,对于提交到仓库中的代码,理论 ...

  10. _mysql.c:29:20: error: Python.h: No such file or directory

    在Centos系统中安装 pip install MySQL-python 提示: _mysql.c:29:20: error: Python.h: No such file or directory ...