【问题标题】:Remove duplicate rows from MySql [duplicate]从 MySql 中删除重复的行 [重复]
【发布时间】:2017-10-11 08:45:44
【问题描述】:

这是我的 mysqSql 表。

m_Id |  m_Mobile |  m_ReceiveFromBranch
________________________________________
1       12345       1
2       12345       5
3       12345       1   //->Duplicate of m_Id 1
4       99999       1
5       88888       2
6       88888       5
7       88888       2   //->Duplicate of m_Id 5

...

如何只删除重复的行?我有超过 10,000 行有很多重复。

【问题讨论】:

  • 你可以关注这个网址:stackoverflow.com/questions/4685173/…
  • @BikashPaul 我想用 m_Mobile 和不同的 m_ReceiveFromBranch 保留行
  • 通常你会用exists子句解决这个问题,但我不能再发布我的答案了。无论如何,链接到的解决方案也有效。

标签: mysql


【解决方案1】:

试试这个

 DELETE a
FROM mytable  as a, mytable  as b
WHERE
  (a.m_mobile   = b.m_mobile )
AND (a.m_ReceiveFromBranch = b.m_ReceiveFromBranch )
AND a.ID < b.ID;

【讨论】:

  • 如何删除?
  • 检查:从 mytable 中删除 a 作为 a,mytable 作为 b WHERE (a.m_mobile = b.m_mobile) AND (a.m_ReceiveFromBranch = b.m_ReceiveFromBranch) AND a.ID
猜你喜欢
  • 2023-04-02
  • 2011-07-18
  • 1970-01-01
  • 1970-01-01
  • 2014-06-01
  • 1970-01-01
  • 2011-03-19
相关资源
最近更新 更多