做地址管理时,需要先根据要设为默认的地址的用户将用户的其他地址都设置为非默认

需要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的更多相关文章

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

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

  3. mysql You can't specify target table 'xxx' for update in FROM clause

    含义:您不能在子句中为更新指定目标表'xxx'. 错误描述:删除语句中直接含select,如下: DELETE FROM meriadianannotation WHERE SeriesID IN ( ...

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

  5. Mysql You can't specify target table 'newsalrecord' for update in FROM clause

    这个问题是不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值.解决办法就是建立个临时的表.

  6. mysql中更新或者删除语句中子语句不能操作同一个表You can't specify target table 'test' for update in FROM clause

    问题描述:有个数据表test,有个字段value,如下 mysql> select * from test;+----+------------------------------------+ ...

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

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

  9. 关于mysql 5.7版本“报[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause”错误的bug

    不同于oracle和sqlserver,mysql并不支持在更新某个表的数据时又查询了它,而查询的数据又做了更新的条件,因此我们需要使用如下的语句绕过: , notice_code ) a) ; 本地 ...

随机推荐

  1. linux安装consul集群

    一.集群规划 consul借助agent来运行,类似elk的logstash agent 或 zabbix监控系统的agent , 每个需要被发现的服务上,通过consul agent client ...

  2. [Spring MVC]学习笔记--DispatcherServlet

    在上一篇我们介绍了Servlet,这一篇主要来看一下MVC中用到的DispatcherServlet(继承自HttpServlet). 1. DispatcherServlet在web.xml中被声明 ...

  3. Win7 maven安装及配置

    1. 前期准备 ① jdk 1.8 ② maven 3.5.4 下载地址:http://maven.apache.org/download.cgi 2. 配置maven环境变量 ① maven解压到指 ...

  4. 【BZOJ2721】[Violet 5]樱花 线性筛素数

    [BZOJ2721][Violet 5]樱花 Description Input Output Sample Input 2 Sample Output 3 HINT 题解:,所以就是求(n!)2的约 ...

  5. UI通过UISlider编写游戏第六感

    #import "RootViewController.h" @interface RootViewController (){    UILabel *scoreLabel; } ...

  6. event对象及各种事件

    事件(event) event对象 (1)什么是event对象? Event 对象代表事件的状态,比如事件在其中发生的元素.键盘按键的状态.鼠标的位置.鼠标按钮的状态.事件通常与函数结合使用,函数不会 ...

  7. 修改 /var/lib/locales/supported.d/local 文件(使用 locale -a 命令查看系统中所有已配置的 locale)

    转自:http://zyxhome.org/wp/cc-prog-lang/c-stdlib-setlocale-usage-note/ http://www.west263.com/info/htm ...

  8. RabbitMQ_消息队列基本使用_2

    简介 RabbitMQ:接受消息再传递消息,可以视为一个“邮局”. 发送者和接受者通过队列来进行交互,队列的大小可以视为无限的,多个发送者可以发生给一个队列,多个接收者也可以从一个队列中接受消息. p ...

  9. 介绍一下except的用法和作用?

    Python的except用来捕获所有异常,因为Python里面的每次错误都会抛出一个异常,所以每个程序的错误都被当作一个运行时错误.

  10. 算法训练 s01串

    问题描述 s01串初始为"0" 按以下方式变换 0变1,1变01 输入格式 1个整数(0~19) 输出格式 n次变换后s01串 样例输入 3 样例输出 101 数据规模和约定 0~ ...