SQL Remove almost duplicate rows

前端 未结 4 1274
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 16:39

I have a table that contains unfortuantely bad data and I\'m trying to filter some out. I am sure that the LName, FName combonation is unique since the data set is small en

4条回答
  •  鱼传尺愫
    2020-12-30 17:05

    Here is a relatively simple query that uses standard SQL and does just this:

    SELECT * FROM Person P
    WHERE Email IS NOT NULL OR -- Take all people with non-null e-mails
          Email IS NULL AND    -- and all people with null e-mails, as long as
            NOT EXISTS         -- there is no duplicate record of the same person
              (SELECT *        -- with a non-null e-mail
               FROM Person P2 
               WHERE P2.LName=P.LName AND P2.FName=P.FName AND P2.Email IS NOT NULL)
    

提交回复
热议问题