How to delete Duplicates in MySQL table

后端 未结 4 1629
耶瑟儿~
耶瑟儿~ 2020-11-27 07:39

I\'ve given a client the following query to delete duplicate phone no. records in an MSSQL database, but now they need to also do it on MySQL, and they report that MySQL com

4条回答
  •  半阙折子戏
    2020-11-27 08:04

    MySQL complains, because it makes no sense. You trying to aggregate using min() column by which you group.

    Now, if you're trying to delete duplicate phone numbers for the same person, the SQL should be:

    delete from bkPhone
     where phoneId not in
     (
             select min(phoneId)
             from bkPhone
             group by firstName,lastName /* i.e. grouping by person and NOT grouping by phoneId */
             having  count(*) >= 1
     )
    

提交回复
热议问题