Share via

find duplicate record

Vineet S 1,390 Reputation points
2024-11-16T08:40:28.9666667+00:00

Hi,

have 3 rows in one table how to remove 2 duplicate from table

1, 2, 3

1, 2, 3

1, 2, 3

Azure SQL Database
Developer technologies | Transact-SQL
Developer technologies | Transact-SQL

A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

Answer accepted by question author

Erland Sommarskog 134.7K Reputation points MVP Volunteer Moderator
2024-11-16T09:12:22.2566667+00:00
; WITH numbering AS (
   SELECT row_number() OVER(PARTITION BY a, b, c ORDER BY somecolumn) AS rowno
   FROM tbl
)
DELETE numbering
WHERE rowno > 1

The column you specify after ORDER BY determines which row you keep. For instance, if you want to keep the most recently inserted column, you would specify

ORDER BY insertdate DESC

This assumes that you actually have a column that tracks when the row was inserted.

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.