ホームページ  >  に質問  >  本文

mysql - 根据一个字段查找另一个字段重复的数据?并删除相同的记录,保留其中一个。

根据一个字段查找另一个字段重复的数据?并删除相同的记录,保留其中一个。

数据库表:product_code_relate_titletext

字段:id,search_id,product_code,raw_title

需求:根据product_code重找raw_title重复的数据?(已实现)

需求:根据product_code重找raw_title重复的数据,并且删除相同的数据,保留id最少的记录即可。

(注意:删除的是product_code下raw_title重复的数据)

select * from product_code_relate_titletext p where (select count(1) from product_code_relate_titletext where product_code=p.product_code and raw_title=p.raw_title)>1  

黄舟黄舟2742日前626

全員に返信(3)返信します

  • 怪我咯

    怪我咯2017-04-17 16:18:10

    delete from product_code_relate_titletext where id not in (select * from (select min(id) from product_code_relate_titletext group by product_code,raw_title having count(*) > 1) as b);

    返事
    0
  • 阿神

    阿神2017-04-17 16:18:10

    リーリー

    返事
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 16:18:10

    あなたのデータがないので、参考のためにコードを提供します:

    リーリー リーリー

    返事
    0
  • キャンセル返事