How to delete duplicates in SQL table based on multiple fields

后端 未结 9 494
星月不相逢
星月不相逢 2020-12-04 14:58

I have a table of games, which is described as follows:

+---------------+-------------+------+-----+---------+----------------+
| Field         | Type                


        
9条回答
  •  离开以前
    2020-12-04 15:26

    select orig.id,
           dupl.id
    from   games   orig, 
           games   dupl
    where  orig.date   =    dupl.date
    and    orig.time   =    dupl.time
    and    orig.hometeam_id = dupl.hometeam_id
    and    orig. awayteam_id = dupl.awayeam_id
    and    orig.locationcity = dupl.locationcity
    and    orig.locationstate = dupl.locationstate
    and    orig.id     <    dupl.id
    

    this should give you the duplicates; you can use it as a subquery to specify IDs to delete.

提交回复
热议问题