• messineo,

    If you have multiple columns that you want to deduplicate on you will need to include all of them in whichever method you use.

    Here is some sample code using each method that should work (all based on the Northwind database). Note that in all these cases the data will be de-duplicated but which row is selected for each set of duplicates can not be predicted (so if you want the first order for each set you will need different code).

    select

    a.ProductID

    ,a.UnitPrice

    ,a.Quantity

    ,a.Discount

    from

    (select

    ProductID

    ,UnitPrice

    ,Quantity

    ,Discount

    ,Rank() over (order by ProductID,UnitPrice,Quantity,Discount) as Ranking

    ,Row_Number() over (order by ProductID,UnitPrice,Quantity,Discount) as RowNumber

    from

    [Order Details]

    ) as a

    where

    a.Ranking=a.RowNumber

    select

    a.ProductID

    ,a.UnitPrice

    ,a.Quantity

    ,a.Discount

    from

    (select

    ProductID

    ,UnitPrice

    ,Quantity

    ,Discount

    ,Row_Number() over (partition by ProductID,UnitPrice,Quantity,Discount order by ProductID) as RowNumber

    from

    [Order Details]

    ) as a

    where

    a.RowNumber=1

    select

    ProductID

    ,UnitPrice

    ,Quantity

    ,Discount

    from

    [Order Details]

    group by

    ProductID

    ,UnitPrice

    ,Quantity

    ,Discount