Min() and max(), a different way to find duplicate

  • 2

    Just for sharing. It can also find the duplicate emails.

    SELECT email 
    FROM (  SELECT email, MIN(id) minid, MAX(id) maxid
            FROM Person 
            GROUP by email ) minmax
    WHERE minid <> maxid

    If change the where condition, we can get the unique ones.

    WHERE minid = maxid

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.