8/30/2012

Removing duplicates from the table

SELECT DISTINCT a.*
  FROM dbo.AssetDealsConnections a
  JOIN dbo.AssetDealsConnections b
  ON a._fk_Asset = b._fk_Asset AND a._fk_stageID = b._fk_stageID AND a._pk != b._pk
  ORDER BY a._fk_Asset, a._pk;


 DELETE b
  FROM dbo.AssetDealsConnections a
  JOIN dbo.AssetDealsConnections b
  ON a._fk_Asset = b._fk_Asset AND a._fk_stageID = b._fk_stageID AND a._pk > b._pk;

No comments:

Post a Comment