I have a table which lists friend relationships, with the following columns: requested_id, requesting_id, connection_type, request_date
In some cases (due to multiple friend requests between the same two members), I end up with duplicate entries in my table.
I am trying to come up with a mysql query which would DELETE, all of the duplicate rows BUT would leave only the most recent row.
I was thinking something along the lines of:
if($duplicatecounter > 1){
mysql_query("DELETE friends WHERE (($id IN (requesting_id, requested_id)) AND ($sid IN (requesting_id, requested_id)))" LIMIT 1) or die("could not delete the rows");
}
But this does only appears to delete one row, but there may be more than only 1 duplicate. And it does not take into consideration the request_date... Any suggestions?