Delete Duplicate Rows form a table can do by using INNER JOIN
Method-1
1 2 3 4 5 | DELETE t1 FROM Students t1 INNER JOIN Students t2 WHERE t1.id < t2.id AND t1.email = t2.email; |
Here If a student’s email Id is duplicated, it will keep the first record of the rows and remove other Same Email ID rows for any students.
If you want to remove the rows from last then we have to change the Query like below
1 2 3 4 5 | DELETE t1 FROM Students t1 INNER JOIN Students t2 WHERE t1.id > t2.id AND t1.email = t2.email; |
Method-2
1 2 3 | DELETE FROM Students WHERE tID NOT IN ( SELECT tID FROM Students GROUP BY email) |