I have a table: ‘person’ with many columns.
I need to return the full row of every entry that does not have a “duplicate” (defined below) along with the following: find the entries in that table that share the properties: first_name, last_name, and work_phone (these are duplicates for my purposes), and return only the entry with the most recent value in its date_modified field, ignoring the rest.
I feel like this is either a rather advanced query, or is deceptively simple. Either way I can’t figure it out. I am using MySQL 5.
Return only entries with the most recent value in its date_modified field, ignoring the rest:
This will work well assuming date_modified is unique for every combination of fields we are grouping on. If not we have to join on a field that is unique, taking one arbitrary UUID (limit 1) satisfying most recent condition.
And finally, return the full row of every entry that does not have a “duplicate”: