find duplicate record

Vineet S 1,310 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
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,071 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,663 questions
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 113.1K Reputation points MVP
    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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