Created
February 16, 2024 18:03
-
-
Save sintret/37690ddcb835cfd05ba30397c359590d to your computer and use it in GitHub Desktop.
Find and delete duplicate data in mysql postgresql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==mysql | |
SELECT employee_id, date FROM attendance group by date,employee_id having count(*) >= 2 | |
DELETE t1 FROM attendance t1 | |
INNER JOIN attendance t2 | |
WHERE | |
t1.id < t2.id AND | |
t1.employee_id = t2.employee_id AND | |
t1.date = t2.date | |
; | |
==postgresql | |
SELECT | |
employee_id, date, | |
COUNT( employee_id) | |
FROM | |
attendance | |
GROUP BY | |
employee_id, date | |
HAVING | |
COUNT( employee_id)> 1 | |
ORDER BY | |
employee_id | |
DELETE FROM | |
attendance a | |
USING attendance b | |
WHERE | |
a.id < b.id | |
AND a.employee_id = b.employee_id | |
AND a.date = b.date | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment