在Mysql中使用表别名删除

时间:2012-07-30 14:58:47

标签: mysql innodb

我尝试删除mysql 5.1表中的重复行

查询是

delete from sessions o where exists (select * from sessions i where i.data=o.data and i.id<>o.id);

但它似乎有效,我读到在mysql中使用表别名删除语句是不可能的,但这是怎么回事:Deleting Records有效吗?

1 个答案:

答案 0 :(得分:0)

尝试此查询 -

DELETE t1 FROM sessions t1
  JOIN (SELECT data, MIN(id) id FROM sessions GROUP BY data) t2
    ON t1.id <> t2.id AND t1.data = t2.data;