In this article I will explain how to delete or remove duplicate records or rows from a datatable in SQL server.
WITH tempTable as
(
SELECT ROW_NUMBER() Over(PARTITION BY Name,Position ORDER BY Name) As RowNumber,* FROM EmployeData
)
SELECT * FROM tempTable
|
WITH tempTable as
(
SELECT ROW_NUMBER() Over(PARTITION BY Name,Position ORDER BY Name) As RowNumber,* FROM EmployeData
)
DELETE FROM
tempTable where RowNumber >1
SELECT * FROM EmployeData order
by Id asc
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|



Subscribe by RSS
Subscribe by Email
11 comments :
hi MR.suresh i want to know About Insteller class can u please give the demo on that u r site is so good and usefull please continue posting thank u
hi MR.suresh i want to know About Insteller class can u please give the demo on that u r site is so good and usefull please continue posting thank u
Hi Suresh.. when i execute this query in sql server it gives me an error :- "Invalid column name 'RowNumber'."
Can you Please help...
Here i taken RowNumber as a just columnname to display result of count i hope you made it as separate column with datatable. please check the query what i written...
I just created a table like u had. Then i ran the above mentiones query in query browser in SQL Server. The output i got is Invalid column name 'RowNumber. Can you explain this. I havent taken any datatable. i just executed the query
Got it....!!!!!
You are awesome - Very very helpful
Recently I had a question in interview as follows
For example my name is Dorababu some of them inserted as Dorababu,Dhorababu and dorebabu like this. I would like to delete the remaining except Dorababu from the table how can I do this
Dear Suresh, Is that only way to find duplicate record and delete them and is that Optimized query?
I don't know how to remove my date to SQL server?
AWESOME!!!!! Thanks a lot.