This my original table:
Intended table:
I can't add a new column to table.
You can delete duplicates using i.e. ROW_NUMBER()
:
with duplicates as
(
select
*
,ROW_NUMBER() OVER (PARTITION BY FirstName, LastName, age ORDER BY FirstName) AS number
from yourTable
)
delete
from duplicates
where number > 1
Each row where number
is bigger than 1 is a duplicate.
You can use a common table expression to delete all but the first record in a set of duplicates:
with cte as (
select *, row_number()
over (partition by FirstName, LastName, Age order by FirstName, LastName, Age) as row_number
from tbl
)
delete from cte where row_number <> 1
You need some way of identifying the rows in the absence of a PK.
The only way I can think of is to:
I'm not positive about this solution, though. I think this answer can help to produce distinctive row ids. I hope it helps.