V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
timepast
V2EX  ›  MySQL

关于 update table_1 set ... where table_1.id = (select table_1.id from table_1 where ...) 的问题

  •  
  •   timepast ·
    idyllim · May 29, 2014 · 5388 views
    This topic created in 4355 days ago, the information mentioned may be changed or developed.
    如题的语句在mysql中报错:You can't specify target table table_1 for update in FROM clause

    解决办法是:
    UPDATE table_1 SET set...
    WHERE
    table_1.x = (
    SELECT pick.id FROM (SELECT tmp.id FROM table_1 tmp WHERE tmp.x = ? AND tmp.x = ?) pick )
    但是这个语句的性能是不是不如分步操作的性能呢?
    3 replies    2014-05-29 16:07:07 +08:00
    Dwyanetalk
        1
    Dwyanetalk  
       May 29, 2014
    不明白这是要干什么?感觉在绕圈子……select后面的where直接当update的where不行吗?
    timepast
        2
    timepast  
    OP
       May 29, 2014
    @Dwyanetalk 报错
    lu18887
        3
    lu18887  
       May 29, 2014
    结合查询计划进行分析吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2650 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 13:07 · PVG 21:07 · LAX 06:07 · JFK 09:07
    ♥ Do have faith in what you're doing.