Chinaunix首页 | 论坛 | 博客
  • 博客访问: 675904
  • 博文数量: 118
  • 博客积分: 2933
  • 博客等级: 少校
  • 技术积分: 1779
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-27 10:16
文章存档

2013年(35)

2012年(27)

2011年(23)

2010年(33)

分类: 数据库开发技术

2012-11-12 10:23:35

错误语句:

DELETE  from teachercontact  where id in(
select  MIN(c.id) as tId  from teachercontact c group by c.teacherId having(count(*)>1)
))

针对以上sql:会出现

You can't specify target table 'teachercontact' for update in FROM clause

修改为:

DELETE  from teachercontact  where id in(
SELECT a.tId FROM (select  MIN(c.id) as tId  from teachercontact c group by c.teacherId having(count(*)>1)
) a)
原因分析:
    mysql中不能这么用。 (等待mysql升级吧)。那串英文错误提示就是说,不能先select出同一表中的某些值.
本人感觉应该是因为之前查找的是同一个teachercontact表导致的,必须在查询和删除之间加上一个中间表。
 
阅读(4070) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~