Azure SQL Database
An Azure relational database service.
5,800 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
have 3 rows in one table how to remove 2 duplicate from table
1, 2, 3
1, 2, 3
1, 2, 3
; 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.