I have duplicate IP Address records in my database like this :
id | ipaddress
1 192.168.xxx.xxx
2 192.168.xxx.xxx
3 111.118.xxx.xxx
4 111.118.xxx.xxx
I want unique ip addresses in my field. How should I delete all duplicate entry?
Thanks
Deleting duplicates in MySQL is a bit tricky because of the stupid restriction that the table cannot be referenced in a sub-select. Therefor the sub-select needs to be re-written into a join:
SQLFiddle demo: http://sqlfiddle.com/#!2/9cfb9c/1
Edit
There is actually a way to get around the stupid sub-select restriction. If the table is wrapped into a derived table inside the sub-select, the MySQL parser doesn’t notice this and happily deletes with a sub-select: