• mysql delete中的查询子句


    1. 查询子句中的表名,不能和delete的表名一样

    例如:

    delete from tb_1 where score = ( select min(score) from tb_1)

    执行时,会报错:1093 - You can't specify target table 'tb_1' for update in FROM clause, Time: 0.002000s

    如果子查询的 from 子句和更新、删除对象使用同一张表,会出现上述错误。

    解决方案:通过给from子句中的结果集起别名

    delete from tb_1 where score = (select a.sc from (select min(score) as sc from  tb_1) as a)

    2. delete from tb_1 这样的子句中table不能使用别名

    delete from tb_1 a where a.id = 8

    以上sql执行时报错:

    1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a where a.id = 8' at line 1, Time: 0.002000s

    解决方案:去掉别名

    delete from tb_1 where id = 8

     ps: select查询语句不影响,select * from tb_1 a where a.id = 4,可正常执行查询

  • 相关阅读:
    table标签去除默认边框
    自定义矢量图
    ClickJacking(点击劫持)
    css 字体不撑开默认块级元素问题
    meate 标签使用介绍
    intellij IDEA15 设置背景颜色
    JS 浮点数运算丢失精度解决方案
    IDEA 滚动条跳动问题
    JS
    异步变同步
  • 原文地址:https://www.cnblogs.com/xiaochongc/p/15621172.html
Copyright © 2020-2023  润新知