{"id":89,"date":"2025-08-09T14:28:54","date_gmt":"2025-08-09T14:28:54","guid":{"rendered":"https:\/\/fhix.fr\/?p=89"},"modified":"2025-09-03T10:23:34","modified_gmt":"2025-09-03T10:23:34","slug":"supprimer-les-doublons-dans-un-fichier","status":"publish","type":"post","link":"https:\/\/fhix.fr\/index.php\/2025\/08\/09\/supprimer-les-doublons-dans-un-fichier\/","title":{"rendered":"Supprimer les doublons dans un fichier"},"content":{"rendered":"\n<p><code><strong>DELETE FROM<\/strong> monfichier a<br><strong>WHERE RRN<\/strong>(a) <strong>NOT IN<\/strong> ( <strong>SELECT MAX<\/strong>(<strong>RRN<\/strong>(b)) <strong>FROM<\/strong> monfichier b <br><strong>WHERE<\/strong> (a.cle1, a.cle2) = (b.cle1, b.cle2) )<\/code><\/p>\n\n\n\n<p><strong>Explications :<\/strong><br>La fonction RRN permet de r\u00e9cup\u00e9rer le num\u00e9ro d&rsquo;enregistrement de la ligne. <br>Le SQL supprime donc les doublons (cl\u00e91+cl\u00e92 dans l&rsquo;exemple) qui ne correspondent pas au dernier num\u00e9ro d&rsquo;enregistrement.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"407\" height=\"146\" src=\"https:\/\/fhix.fr\/wp-content\/uploads\/2025\/08\/image-1.png\" alt=\"\" class=\"wp-image-163\" srcset=\"https:\/\/fhix.fr\/wp-content\/uploads\/2025\/08\/image-1.png 407w, https:\/\/fhix.fr\/wp-content\/uploads\/2025\/08\/image-1-300x108.png 300w\" sizes=\"auto, (max-width: 407px) 100vw, 407px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Si on veut conserver le premier doublon et non le dernier doublon, il faut remplacer MAX par MIN :<br><code><strong>DELETE FROM<\/strong> monfichier a<br><strong>WHERE RRN<\/strong>(a) <strong>NOT IN<\/strong> ( <strong>SELECT MIN<\/strong>(<strong>RRN<\/strong>(b)) <strong>FROM<\/strong> monfichier b <br><strong>WHERE<\/strong> (a.cle1, a.cle2) = (b.cle1, b.cle2) )<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"406\" height=\"145\" src=\"https:\/\/fhix.fr\/wp-content\/uploads\/2025\/08\/image-2.png\" alt=\"\" class=\"wp-image-164\" srcset=\"https:\/\/fhix.fr\/wp-content\/uploads\/2025\/08\/image-2.png 406w, https:\/\/fhix.fr\/wp-content\/uploads\/2025\/08\/image-2-300x107.png 300w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Pour simplement chercher les doublons, on peut utiliser :<br><code><strong>SELECT<\/strong> *<strong> FROM<\/strong> monfichier a<br><strong>WHERE RRN<\/strong>(a) <strong>NOT IN<\/strong> ( <strong>SELECT <\/strong><strong>RRN<\/strong>(b) <strong>FROM<\/strong> monfichier b <br><strong>WHERE<\/strong> (a.cle1, a.cle2) = (b.cle1, b.cle2) )<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>DELETE FROM monfichier aWHERE RRN(a) NOT IN ( SELECT MAX(RRN(b)) FROM monfichier b WHERE (a.cle1, a.cle2) = (b.cle1, b.cle2) ) Explications :La fonction RRN permet de r\u00e9cup\u00e9rer le num\u00e9ro d&rsquo;enregistrement de la ligne. Le SQL supprime donc les doublons (cl\u00e91+cl\u00e92 dans l&rsquo;exemple) qui ne correspondent pas au dernier num\u00e9ro d&rsquo;enregistrement. Si on veut conserver le &#8230; <a title=\"Supprimer les doublons dans un fichier\" class=\"read-more\" href=\"https:\/\/fhix.fr\/index.php\/2025\/08\/09\/supprimer-les-doublons-dans-un-fichier\/\" aria-label=\"En savoir plus sur Supprimer les doublons dans un fichier\">Lire la suite<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-sql-db2"],"_links":{"self":[{"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":7,"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fhix.fr\/index.php\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}