在MySQL中使用表别名删除 [英] Delete with table alias in Mysql

查看:150
本文介绍了在MySQL中使用表别名删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am try to delete duplicate rows in mysql 5.1 table

查询是

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

但是它似乎起作用了,我读到不能在MySQL中为删除语句使用表别名,但这是怎么做的:

But it dosent seem to work, I read that using table alias for delete statements in mysql is not possible, but how does this: Deleting Records work?

推荐答案

尝试此查询-

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;

这篇关于在MySQL中使用表别名删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆