【问题标题】:SQL Remove Row That Has The Same Values Into New Table [duplicate]SQL将具有相同值的行删除到新表中[重复]
【发布时间】:2012-09-27 18:15:26
【问题描述】:

可能重复:
Remove Duplicate Rows Leaving Oldest Row Only?
MySQL remove duplicate rows

假设我有以下表格库:int logicalid(pk) ,int home, int person 说我有以下记录...
1,5,6
2,5,6
3,5,5
4,5,5

查询后,我只想在新表中放入具有相同 home,person 列值的一行,因此这将是输出结果:
1,5,6
2,5,5
有什么想法吗??

【问题讨论】:

    标签: mysql sql database


    【解决方案1】:

    使用 id 的自动递增列创建新表。

    然后插入到表中,使用如下查询:

    insert into newTable(home, person)
        select distinct home, person
        from oldTable
    

    【讨论】:

      【解决方案2】:

      INSERT INTO newtable(home, person) SELECT DISTINCT home, person FROM sourcetable

      【讨论】:

        猜你喜欢
        • 2017-03-02
        • 2018-02-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-23
        • 2015-11-30
        相关资源
        最近更新 更多