mysql - 根据一个字段查找另一个字段重复的数据?并删除相同的记录,保留其中一个。
黄舟
黄舟 2017-04-17 16:16:10
0
3
620

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

数据库表: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  

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全員に返信(3)
刘奇

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
阿神

リーリー

いいねを押す +0
伊谢尔伦

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

リーリー リーリー
いいねを押す +0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!