28 lines
777 B
Plaintext
28 lines
777 B
Plaintext
====== Trouver les doublons ======
|
|
|
|
{{ :informatique:langage:sql:sql_table_records.jpg?nolink&75x75|Trouver des doublons en SQL}}
|
|
|
|
~~NOTOC~~
|
|
|
|
<panel type="default" title="Code SQL">
|
|
<code SQL [enable_line_numbers="true", start_line_numbers_at="1"]>
|
|
SELECT COUNT(*) AS nbr_doublon, champ1, champ2, champ3
|
|
FROM table
|
|
GROUP BY champ1, champ2, champ3
|
|
HAVING COUNT(*) > 1
|
|
</code>
|
|
</panel>
|
|
|
|
<panel type="default" title="Code SQL">
|
|
<code SQL [enable_line_numbers="true", start_line_numbers_at="1"]>
|
|
SELECT DISTINCT *
|
|
FROM table t1
|
|
WHERE EXISTS (
|
|
SELECT *
|
|
FROM table t2
|
|
WHERE t1.ID <> t2.ID
|
|
AND t1.champ1 = t2.champ1
|
|
AND t1.champ2 = t2.champ2
|
|
AND t1.champ3 = t2.champ3 )
|
|
</code>
|
|
</panel> |