1
Good morning guys, I read some articles here with similar problems, but none of them answered my question, what I want. Here’s the thing:
I have a query to check which lines have a duplicate field
SELECT IP, Count(*) FROM hardware GROUP BY IP HAVING Count(*) > 1
Possession of the information of which ips are duplicated, I capture the data from the IP field in a variable and delete:
DELETE FROM hardware WHERE IP = '{$ip}'
Works well, but I would like to delete only the oldest record, keeping the latest.
Does anyone have any idea?
Possible duplicate of How to remove duplicate lines efficiently?
– riki481
Create an Insert Trigger for that table, so when a value is inserted the Trigger is triggered and you replace the old ip with the new one. I have never made a Trigger with Mysql, but with MSSQL it is very simple to do.
– Juciano Victor
Possible duplicate of How to delete all duplicates except one?
– Sorack