Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4561682
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:06:34+00:00 2026-05-21T18:06:34+00:00

I have a table: ‘person’ with many columns. I need to return the full

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T18:06:35+00:00Added an answer on May 21, 2026 at 6:06 pm

    Return only entries with the most recent value in its date_modified field, ignoring the rest:

    SELECT p.* FROM
      ( SELECT max(date_modified) as most_recent_date 
        FROM person 
        GROUP BY first_name,last_name,work_phone ) p1
    JOIN person p
    ON p.date_modified = p1.most_recent_date
    

    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.

    SELECT p.* FROM
      ( SELECT *,max(date_modified) as most_recent_date 
        FROM person 
        GROUP BY first_name,last_name,work_phone ) p1
    JOIN person p
    ON p.UUID =
      ( SELECT p_uniq.UUID 
        FROM person p_uniq
        WHERE p_uniq.first_name = p1.first_name
          AND p_uniq.last_name = p1.last_name
          AND p_uniq.work_phone = p1.work_phone
          AND p_uniq.date_modified = p1.most_recent_date
        LIMIT 1 )
    

    And finally, return the full row of every entry that does not have a “duplicate”:

    SELECT * , count( * ) AS entries
    FROM `person`
    GROUP BY first_name, last_name, work_phone
    HAVING entries =1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with pageId, parentPageId, title columns. Is there a way to return
I have table containing data . In every row there is a checkbox plus
i have table consist of columns : id,name,job and i have row stored with
I have table with 3 columns: id (of person), city (which person visited) and
I have table in SQL Server 2005 that contains two columns Fruit and Colour
I have a table in a SQL Server 2005 database with a trigger that
I have a table which is full of arbitrarily formatted phone numbers, like this
I have table with some fields that the value will be 1 0. This
I have table that has a column of type DateTime, I would like to
I have table with two columns: ItemMaster (Item INT, Quantity INT) If an item

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.