zoukankan      html  css  js  c++  java
  • mysql 操作

    MySql报错: You can't specify target table 'table name' for update in FROM clause

    2008-09-17 13:51天上人间兮 | 分类:数据库DB | 浏览43478次
    在Mysql下执行: delete   from   blur_article    where   id   not   in(select   min(id)   from  blur_article    group   by   title)
    用途是去重复标题,但是却报错! #1093 - You can't specify target table 'blur_article' for update in FROM clause
    在Mysql下执行: select * from blur_article where id not in(select min(id) from blur_article group by title) 执行查询语句却显示成功!
    怎么回事呀,如果上面的delete不能执行,有没有别的sql可以做这样的操作?
    我是想做一个去重复操作,比如说: 字段          id       title                  1           张三                  2           李四                  3           张三                  4           王五                  5           李四   
    最终结果是 id title 1 张三 2 李四 4 王五
     
     
    mysql中不能这么用。 (等待mysql升级吧) 错误提示就是说,不能先select出同一表中的某些值,再update这个表(在同一语句中) 
    替换方案: create table tmp as select min(id) as col1 from blur_article group by title; delete from blur_article where id not in (select col1 from tmp); drop table tmp;
    已经测试,尽请使用
  • 相关阅读:
    redis学习
    Ubuntu命令大全
    关于jquery中attr和prop的用法
    Ubuntu下修改为永久DNS的方法
    Yii2 behaviors中verbs access的一些理解
    vue_ form表单 v-model
    vue-one_demo_music
    ES6
    VUE 入门 01
    Django model.py表单设置默认值允许为空
  • 原文地址:https://www.cnblogs.com/zhenfeng/p/4444178.html
Copyright © 2011-2022 走看看