DELETE QUERY WHICH CONTAIN DUPLICATE RECORD IN TABLE
Consider we have test table with column (Id, Name )
Here i want to delete record which is duplicate
Write down this query
declare @rowcount int
set @rowcount = (select distinct count(*) OVER (PARTITION BY name) as cnt from test where name='test' )
set @rowcount = @rowcount - 1
delete top(@rowcount) from test where name='test'
print 'Record Deleted'
output
Consider we have test table with column (Id, Name )
Here i want to delete record which is duplicate
Write down this query
declare @rowcount int
set @rowcount = (select distinct count(*) OVER (PARTITION BY name) as cnt from test where name='test' )
set @rowcount = @rowcount - 1
delete top(@rowcount) from test where name='test'
print 'Record Deleted'
output
No comments:
Post a Comment