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. 【Professional English】Words Summary

    01.数据库管理系统(Database Management Systems,DBMS) A database management system (DBMS) is a computer softw ...

  2. 05-老马jQuery教程-动画

    前言 jQuery的动画系统做的非常出色,而且把最常用的显示.隐藏.淡入淡出.滑动显示和折叠凳效果都做了很好的封装.跟jQuery的选择器和事件配合起来,可以实现很多很绚的效果,而且简单易用兼容性好. ...

  3. Android开发(十一)——ImageView的尺寸设置scaleType

    ImageView的属性android:scaleType,即 ImageView.setScaleType(ImageView.ScaleType). android:scaleType是控制图片如 ...

  4. tomcat8.5性能优化

    主要是按照两篇文章,部分参数因适配Tomcat8.5进行了调整 一.有关 JAVA_OPTS http://www.open-open.com/lib/view/open1401931407228.h ...

  5. ARKit从入门到精通(7)-ARCamera介绍

    ARCamera是一个相机,它是连接虚拟场景与现实场景之间的枢纽.在ARKit中,它是捕捉现实图像的相机,在SceneKit中它又是3D虚拟世界中的相机.(一般第一人称3D游戏,主角其实就是一个3D相 ...

  6. 基于jQuery和CSS3炫酷图片3D旋转幻灯片特效

    在线预览   源码下载 iPresenter是一款效果非常炫酷的jQuery和CSS3 3D旋转幻灯片特效插件.你可以使用它来制作产品展示.图片画廊或者各种幻灯片和轮播图特效.这款幻灯片插件的特点有: ...

  7. Windows获取远程Linux局域网内的mysql连接

    求:本地Windows7电脑,通过xshell和xftp能够连接远程Linux服务器,但是数据库不在这台服务器上,在Linux服务器的局域网里面: 需要当前本地Windows7电脑能够连接Linux服 ...

  8. laravel iis搭建

    1.urlrewrite https://www.iis.net/downloads/microsoft/url-rewrite 2.安装phpmanager 3.目录定位到public 赋给iuse ...

  9. error "OPatch cannot find a valid oraInst.loc file to locate Central Inventory

    Error tersebut terjadi ketika akan menjalankan command opatch lsinventory untuk mengetahui patch yan ...

  10. [转]oracle存储过程中update不成功的一个原因

    原文地址:http://lin49940.iteye.com/blog/466626 今天一个同事写oracle 的存储过程遇到了一个问题, 他在里面update 操作不能完成更新的操作, 但是又不会 ...