EMP
-------
EMPNO
-----------
1
1
2
3
3
4
4
4
5
6
Write a DELETE
statement to delete the duplicate rows. After running your Delete
statement, one occurrence of each value of Empno
should remain in the table.
EMP
-------
EMPNO
-----------
1
1
2
3
3
4
4
4
5
6
Write a DELETE
statement to delete the duplicate rows. After running your Delete
statement, one occurrence of each value of Empno
should remain in the table.
simplest thing is define unique constraint on that column so it will not take duplicate values and if there are then it will auto delete
Or Try below query
DELETE e.*
FROM emp1 e
WHERE empno IN
(SELECT empno
FROM (SELECT MIN(e1.empno) as empno
FROM emp1 e1
GROUP BY e1.empno
HAVING COUNT(*) > 1) x);
Or you can see this example also Delete all Duplicate Rows except for One in MySQL?