Tuesday, March 27, 2012

Remove or Delete duplicate records in a table in MySQL

Remove the duplicate records in a table, it will delete records which is having greater than the sno

For example: table name: players

snonamecoach_id
1Sachin1
2Sachin5
3Kohli1
4Ganguly2
5Kohli4
6Gambir3

Query:
DELETE FROM players USING players , players AS virtualtable
WHERE players .sno > virtualtable.sno
AND players .name = virtualtable.name

Output:
snonamecoach_id
1Sachin1
3Kohli1
4Ganguly2
6Gambir3

No comments:

Post a Comment