zoukankan      html  css  js  c++  java
  • mysql delete 注意

    mysql中You can't specify target table <tbl> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。

    例如下面这个sql: 报错

    DELETE from monthxl  where dateTime in 
    (
    	SELECT a.dateTime  from monthxl a  where a.dateTime !=(
    		select max(b.dateTime) from monthxl b where a.month=b.month
    	) 
    )  

    修改如下:

    DELETE FROM monthxl where dateTime in 
    ( select b.dateTime from ( -- 用临时表 包装一层 再删除 SELECT a.month,a.dateTime from monthxl a where a.dateTime !=( select max(b.dateTime) from monthxl b where a.month=b.month ) ) b )

      

  • 相关阅读:
    Adobe Flash Player 设置鼠标点不到允许或者拒绝!
    bzoj2096
    bzoj2789
    LA3353
    poj2594
    bzoj2427
    bzoj1076
    bzoj2818
    bzoj3668
    bzoj2006
  • 原文地址:https://www.cnblogs.com/GotoJava/p/7493955.html
Copyright © 2011-2022 走看看