`
SSailYang
  • 浏览: 308704 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

MySQL update 中 select clause 的一个问题

阅读更多

 

今天遇到的问题,随口说一句。

 

MySQL 中,如果 update 语句中含有 select 子句,那么update 的表和 select 子句中的表不能是一个。否则会得到“You can't specify target table <Table Name> for update in FROM clause” 的错误消息。解决方法是在 select 子句的 from 不直接用表名,而是用一个另外一个 select 语句得到一个临时表。

 

update <Table Name> set xxx=xxx where
  (
    select * from (select tmp.* from <Table Name> tmp) a
      where something
  ) = something
 

 

分享到:
评论

相关推荐

    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这个表(在同一语句中)。 例如下面这个sql: 代码如下: delete from tbl where id in ...

    MySQL报错1093 – You can’t specify target table ‘t’ for update in FROM clause, Time: 0

    1093 – You can’t specify target table ‘t’ for update in FROM clause, Time: 0 前情提示: Mac OS10.14+MySQL8.0.18; centOS6.8final+MySQL5.6; 解决: 方法一:多嵌套一层。多来一层子查询 以上SQL修改...

    mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法

    最近在处理一些数据库中数据的时候,写了下面的这一条sql语句: UPDATE f_student SET school_id = 0 WHERE id &gt; ( SELECT id FROM f_student WHERE school_id = M LIMIT 1 ) AND id &lt; ( ( SELECT id...

    MySQL UPDATE 更新

    MySQL UPDATE 更新 如果我们需要修改或更新 MySQL 中的数据,我们...你可以在一个单独表中同时更新数据。 当你需要更新数据表中指定行的数据时 WHERE 子句是非常有用的。 通过命令提示符更新数据 以下我们将在 S

    MySQL数据库同时查询更新同一张表的方法

    在平常的项目中,经常会碰到这样的问题:我需要在一张标中同时更新和查询出来的...结果却报错,报错信息为:You can't specify target table 'tb_test' for update in FROM clause,不能在同一语句中update,select同

    MySql存储过程编程.chm

    Using SELECT Statements with an INTO Clause Section 5.3. Creating and Using Cursors Section 5.4. Using Unbounded SELECT Statements Section 5.5. Performing Dynamic SQL with Prepared Statements ...

    Delphi7.1 Update

    not all of the features mentioned in this file are available inall editions of the product.This update resolves the following issues:IDE* Using the up/down arrow keys to navigate and select items from...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

    说明:Oracle中要删除一个用户,必须要具有dba的权限。而且不能删除当前用户,如果删除的用户有数据对象,那么必须加上关键字cascade。 用法:drop user 用户名 [cascade] 四、 用户权限与角色 1. 权限 Oracle中权限...

    SqliteDev 384

    同时能够跟很多程序语言相结合 比如 Tcl C# PHP Java等 还有ODBC接口 同样比起Mysql PostgreSQL这两款开源世界著名的数据库管理系统来讲 它的处理速度比他们都快 SQLite第一个Alpha版本诞生于2000年5月 至今已经有10...

    SQLite(SqliteDev)

    储存在单一磁盘文件中的一个完整的数据库  4. 数据库文件可以在不同字节顺序的机器间自由的共享  5. 支持数据库大小至2TB  6. 足够小, 大致3万行C代码, 250K  7. 比一些流行的数据库在大部分普通数据库操作要快...

    Doctrine ORM for PHP.pdf

    Table of Contents Introduction....................................................................................................13 Code Examples.........................................................

Global site tag (gtag.js) - Google Analytics