I have a table that looks like this
Table1
Id, Name
How can I write a query that delete all rows with duplicate names but kee
Simply you can do this with using cursors the query might be like this
declare @id int declare @name nvarchar(30)
declare cr cursor for select id,name from idnametbl order by id
for update
open cr
fetch next from cr into @id,@name
while @@fetch_status=0
begin
delete from idnametbl where id> @id and name=@name
fetch next from cr into @id,@name
end
close cr
deallocate cr