i have table: 'person' many columns. need return full row of every entry not have "duplicate" (defined below) along following: find entries in table share properties: first_name, last_name, , work_phone (these duplicates purposes), , return entry recent value in date_modified field, ignoring rest.
i feel either rather advanced query, or deceptively simple. either way can't figure out. using mysql 5.
return entries recent value in date_modified field, ignoring rest:
select p.* ( select max(date_modified) most_recent_date person group first_name,last_name,work_phone ) p1 join person p on p.date_modified = p1.most_recent_date
this work assuming date_modified unique every combination of fields grouping on. if not have join on field unique, taking 1 arbitrary uuid (limit 1) satisfying recent condition.
select p.* ( select *,max(date_modified) most_recent_date person group first_name,last_name,work_phone ) p1 join person p on p.uuid = ( select p_uniq.uuid person p_uniq p_uniq.first_name = p1.first_name , p_uniq.last_name = p1.last_name , p_uniq.work_phone = p1.work_phone , p_uniq.date_modified = p1.most_recent_date limit 1 )
and finally, return full row of every entry not have "duplicate":
select * , count( * ) entries `person` group first_name, last_name, work_phone having entries =1
Comments
Post a Comment