|
EMP |
ID |
Country |
Capital |
1 |
France |
Paris |
2 |
USA |
Washington |
3 |
France |
Paris |
4 |
India |
New Delhi |
5 |
USA |
Washington |
|
---- We can only use this method, if we have ID Column and Duplicate Rows occurs only 2 times
---- Find Duplicate Rows
SELECT MAX(ID) as ID, Country, Capital FROM EMP
GROUP BY Country, Capital
HAVING COUNT(*) > 1
Output |
ID |
Country |
Capital |
3 |
France |
Paris |
5 |
USA |
Washington |
---- Delete Duplicate Rows
DELETE FROM EMP
WHERE ID IN(
SELECT MAX(ID) FROM EMP
GROUP BY Country, Capital
HAVING COUNT(*) > 1)
|
Output |
Country |
Capital |
France |
Paris |
India |
New Delhi |
USA |
Washington |
|