Delete script SQL Server 2008

后端 未结 2 693
别那么骄傲
别那么骄傲 2021-01-24 02:50

Here is a situation that I am trying to resolve. I have a table that is loaded with duplicates. It happened because similar rows were loaded from two different sources. That is

2条回答
  •  悲&欢浪女
    2021-01-24 03:14

    1. I think the key word INTERSECT isn't used properly. The explanation is below. You could follow the link to get detail.

    EXCEPT returns any distinct values from the left query that are not also found on the right query. INTERSECT returns any distinct values that are returned by both the query on the left and right sides of the INTERSECT operand

    http://msdn.microsoft.com/zh-cn/library/ms188055.aspx

    1. To achieve your perpose, you could try the command merge.

      ;
      merge into #Clevland as target
      using  #Ohio as source
      on (target.UID = source.UID) -- you could add ADDRESS,City,State,Zip
      when not matched
         insert into target (UID) values (source.UID)
      ;
      

    Wish this will help.

提交回复
热议问题