ycs8648
ycs8648
采纳率0%
2018-09-26 08:32 浏览 5.4k

mysql如何删除重复数据只保留一条(全字段去复)?

没有主键,全字段去重,在不建立临时表的情况下可能做到吗???

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答 默认 最新

  • m0_37532969 LiuZh__ZY 2018-09-26 08:44

    DELETE
    FROM
    table a
    WHERE
    (a.id, a.seq) IN (
    SELECT
    id,
    seq
    FROM
    table
    GROUP BY
    id,
    seq
    HAVING
    count(*) > 1
    )
    AND rowid NOT IN (
    SELECT
    min(rowid)
    FROM
    table
    GROUP BY
    id,
    seq
    HAVING
    count(*) > 1
    )

    点赞 评论 复制链接分享
  • caozhy 从今以后生命中的每一秒都属于我爱的人 2018-09-26 08:47

    select distinct a from ((select 字段1 a from table) union (select 字段2 a from table) union (select 字段3 a from table) union ... )

    点赞 评论 复制链接分享

相关推荐