Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Delete Duplicate Rows

Posted on April 29, 2013October 26, 2015 By David Kittell
CREATE TABLE DuplicateRcordTable (Col1 INT, Col2 INT)
INSERT INTO DuplicateRcordTable
SELECT 1, 1
UNION ALL
SELECT 1, 1 --duplicate
UNION ALL
SELECT 1, 1 --duplicate
UNION ALL
SELECT 1, 2
UNION ALL
SELECT 1, 2 --duplicate
UNION ALL
SELECT 1, 3
UNION ALL
SELECT 1, 4
GO
SELECT *
FROM DuplicateRcordTable
GO
WITH CTE (COl1,Col2, DuplicateCount)
AS
(
SELECT COl1,Col2,
ROW_NUMBER() OVER(PARTITION BY COl1,Col2 ORDER BY Col1) AS DuplicateCount
FROM DuplicateRcordTable
)
DELETE
FROM CTE
WHERE DuplicateCount > 1
GO
SELECT *
FROM DuplicateRcordTable
GO

Reference: http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/

Originally Posted on April 29, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code MSSQL

Post navigation

Previous post
Next post

Related Posts

PowerShell Select-String – UNIX Grep Equivalent

Posted on November 12, 2015

UNIX Terminal commands can really speed things up, take grep for example if you are not sure of where you put a file or if some text is in a file you can run a simple command like this. Find all references to “www.domain.com” grep -R ‘www.domain.com’ /var/www/html PowerShell has…

Read More

PowerShell – Test Port

Posted on January 9, 2017

Similar to CMD Telnet this PowerShell will test a port for you based on certain parameters. function Test-Port { Param( [parameter(ParameterSetName=’ComputerName’, Position=0)] [string] $ComputerName, [parameter(ParameterSetName=’IP’, Position=0)] [System.Net.IPAddress] $IPAddress, [parameter(Mandatory=$true , Position=1)] [int] $Port, [parameter(Mandatory=$true, Position=2)] [ValidateSet("TCP", "UDP")] [string] $Protocol ) $RemoteServer = If ([string]::IsNullOrEmpty($ComputerName)) {$IPAddress} Else {$ComputerName}; If ($Protocol -eq…

Read More

Get Number Of Business Days Between Two Dates

Posted on July 31, 2013October 26, 2015

CREATE FUNCTION fnBusinessDays ( @StartDate DATETIME ,@EndDate DATETIME ) RETURNS INT AS BEGIN IF ( @StartDate IS NULL OR @EndDate IS NULL ) RETURN (0) DECLARE @i INT = 0; WHILE (@StartDate <= @EndDate) BEGIN SET @i = @i + CASE WHEN datepart(dw, @StartDate) BETWEEN 2 AND 6 THEN 1…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes