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

需要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. Collection Set List 集合二

    Set List 都继承Collection Collection:元素之间没有顺序,允许重复和多个null元素对象. Set:元素之间没有顺序,不允许重复只能存一个null. List:元素之间有顺 ...

  2. 【BZOJ4771】七彩树 主席树+树链的并

    [BZOJ4771]七彩树 Description 给定一棵n个点的有根树,编号依次为1到n,其中1号点是根节点.每个节点都被染上了某一种颜色,其中第i个节点的颜色为c[i].如果c[i]=c[j], ...

  3. 贝叶斯网(2)Netica:从数据中学习CPT

    1. 离散节点 在官方Tutorial中是有详细的案例的,就是B篇3.3节,你可以动手把天气预报这个实现一下: http://www.norsys.com/tutorials/netica/secB/ ...

  4. Java输入输出重定向代码

    try {   BufferedInputStream in = new BufferedInputStream(new FileInputStream("input.txt")) ...

  5. BAPI: TRANSACTION_BEGIN的作用

    大概知道是启动一个新会话, CALL FUNCTION 'TRANSACTION_BEGIN' 业务数据处理, CALL FUNCTION 'TRANSACTION_END' 详细功能不清楚. CLE ...

  6. ABAP发邮件函数

    步骤: 一.检查输入参数, (1)未指定文件類別代碼,(2)未指定郵件主題, (3)未指定郵件內容, (4)未指定發送人郵件地址, (5)未指定接收人郵件地址, 二.调用发送功能, (1)创建发送请求 ...

  7. Java中的异常和处理详解(转发:https://www.cnblogs.com/lulipro/p/7504267.html)

    简介 程序运行时,发生的不被期望的事件,它阻止了程序按照程序员的预期正常执行,这就是异常.异常发生时,是任程序自生自灭,立刻退出终止,还是输出错误给用户?或者用C语言风格:用函数返回值作为执行状态?. ...

  8. MySQL的SQL MODE

    SQL MODE:定义mysqld对约束等的响应行为:    查看当前模式:        mysql> SHOW GLOBAL VARIABLES LIKE 'sql_mode';    修改 ...

  9. 和openjdk在一起的第一天-第一次接触有些生疏,就先熟悉一下吧

    暂时搞到了openjdk7,就将就着看吧,(为什么csdn全部都是收费啊,llllj),但是还是决定先读这个openjdk7 还有,不知道怎么的就想试试markdown,也不知道好用不 hello w ...

  10. PL/SQL不能格式化SQL:--PL/SQL Beautifier could not parse text

    PL/SQL sql语句美化器点击没有反应.查看下面提示PL/SQL Beautifier could not parse text.本人此次产生的原因是sql语句语法错误. 工具栏处(如果没有此按钮 ...