Mysql -- You can't specify target table 'address' for update in FROM clause
做地址管理时,需要先根据要设为默认的地址的用户将用户的其他地址都设置为非默认
需要select出用户id然后update
原语句
update address set isdeafult = 0 where user_id = (select user_id from address where id = ?)
报错 -- You can't specify target table 'address' for update in FROM clause
大意是不能先select出同一表中的某些值,再update这个表(在同一语句中)
修改后的语句如下
UPDATE address a INNER JOIN (SELECT user_id FROM address WHERE id = #{id}) c SET a.isdeafult = 0 WHERE a.user_id = c.user_id
解析
select * from address a INNER JOIN
(SELECT user_id FROM address WHERE id = 1) c WHERE a.user_id = c.user_id
的内容完全等于 select * from address ,本质上就是用inner join做了个中间表查询
注 : 只有在mysql中才有这个错误
Mysql -- You can't specify target table 'address' for update in FROM clause的更多相关文章
- mysql You can't specify target table 'sys_org_relation' 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 'xxx' for update in FROM clause的解决
DELETE from sp_goodscontent where goodsId in (SELECT t.goodsId from ( SELECT goodsId FROM sp_goodsco ...
- mysql You can't specify target table 'xxx' for update in FROM clause
含义:您不能在子句中为更新指定目标表'xxx'. 错误描述:删除语句中直接含select,如下: DELETE FROM meriadianannotation WHERE SeriesID IN ( ...
- mysql You can't specify target table 'sys_right_menu' for update in FROM clause (不能从Objor子句中指定目标表“SysRyType菜单)
错误语句: DELETE from sys_right_menu where right_id in (SELECT m.right_id from sys_right_menu mLEFT JO ...
- Mysql You can't specify target table 'newsalrecord' for update in FROM clause
这个问题是不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值.解决办法就是建立个临时的表.
- mysql中更新或者删除语句中子语句不能操作同一个表You can't specify target table 'test' for update in FROM clause
问题描述:有个数据表test,有个字段value,如下 mysql> select * from test;+----+------------------------------------+ ...
- Mysql update in报错 [Err] 1093 - You can't specify target table 'company_info' for update in FROM clause
Mysql update in报错 解决方案: [Err] 1093 - You can't specify target table 'company_info' for update in FRO ...
- MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause
MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause 201 ...
- 关于mysql 5.7版本“报[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause”错误的bug
不同于oracle和sqlserver,mysql并不支持在更新某个表的数据时又查询了它,而查询的数据又做了更新的条件,因此我们需要使用如下的语句绕过: , notice_code ) a) ; 本地 ...
随机推荐
- Android开发:《Gradle Recipes for Android》阅读笔记(翻译)2.3——用Eclipse ADT导出App
问题: 想在一个已经存在的Eclipse ADT的项目中使用Gradle 解决方案: Eclipse ADT插件可以帮助生成Gradle文件 讨论: Eclipse的ADT插件是在2013年推出Gra ...
- vfptr(2)
//i_vptr struct i_vptr { ; }; //vptr.h #include "i_vptr.h" #include <iostream> class ...
- 第三章 T-SQL 编程
3.1 使用变量 变量是可以存储数据值的对象.可以使用局部变量向SQL语句传递数据.在T-SQL中执行一批SQL语句时,可以声明许多变量以便临时使用.声明变量以后,可以在批处理中用一条T-SQL语句设 ...
- SharePoint服务器端对象模型 之 对象模型概述(Part 1)
在一个传统的ASP.NET开发过程中,我们往往会把开发分为界面展现层.逻辑业务层和数据访问层这三个层面.作为一个应用开发平台,SharePoint是微软在直观的开发能力和自由的扩展能力之间,取到的一个 ...
- 将DataTable转换成Json格式
方法一: 将DataTable数据拼接成json字符串,方法如下: ///<summary> /// dataTable转换成Json格式 ///</summary> ///& ...
- java.lang.ClassFormatError: Truncated class file
之前跑的很好的程序,因为我本地IDE出了问题的原因,倒是编译的错误的class文件,结果点击的时候报这样的错误,后来重新clean了工程,重新打包解压启动,问题依旧. 解决办法: 把tomcat的wo ...
- js split 的用法和定义 js split分割字符串成数组的实例代码
关于js split的用法,我们经常用来将字符串分割为数组方便后续操作,今天写一段广告判断代码的时候,竟然忘了split的用法了,特整理下,方便需要的朋友, 关于js split的用法其它也不多说什么 ...
- 博文分类索引--Python
Python 基础 [python]-- 初识python [python]-- 基本语法.循环 [python]-- 列表 [python]-- 元组.字典 [python]-- 字符串.字符编码与 ...
- mustache模板技术(转)
项目首页:http://mustache.github.com/ 项目文档:http://mustache.github.com/mustache.5.html Demo: http://mus ...
- Map.Entry<K,V>分析
一.好处 你是否已经对每次从Map中取得关键字然后再取得相应的值感觉厌倦? Set keys = map.keySet( ); if(keys != null) { Iterator iterator ...