Introduction:
Sometimes, some duplicate data may be inserted in the SQL table. But it's harmful to you and your application too. So how do you remove the duplicate rows in your table?
Description
Take a look at the following table content. It has duplicate rows.
Id | Name | Department |
1 | Arka | .NET |
2 | Ashok | .NET |
3 | Anubhav | PHP |
4 | Arka | .NET |
5 | Sudeshna | Graphics |
Row 1 and 4 are duplicates. So we have to remove one row and keep one in the table. Now the question is how to do this?
Using the Code
To solve this problem, take a look at the following code. This will solve this problem.
WITH tblTemp as
(
SELECT ROW_NUMBER() Over(PARTITION BY Name,Department ORDER BY Name)
As RowNumber,* FROM <table_name>
)
DELETE FROM tblTemp where RowNumber >1
You can find more about SQL here.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI got what i am seraching from last few days in your Blog. I hope you will share more info about it. Please keep sharing.
ReplyDeleteLaptop Service center in Ameerpet
Dell Service center in Ameerpet
HP Service center in Ameerpet
Lenovo Service center in Ameerpet
This comment has been removed by the author.
ReplyDeleteUNIRAJ BCOM 3rd Year Result 2020
ReplyDeleteUOK BCOM 3rd Year Result 2020
ju BCOM 3rd Year Result 2020
You’d outstanding guidelines there. I did a search about the field and identified that very likely the majority will agree with your web page.
Here is the site(http://www.bcomexamresult.in) where you get all Bcom Exam Results. This site helps to clear your all query.
ReplyDeleteSdsuv University BCOM 3rd Year Result 2020
Vikram University BCOM 3rd Year Result 2020
BA 3rd year Result 2019-20
Improve the Software Carrier to Get the Information Technologies Experiences in an best software training course for freshers and experience to upgrade the next level in an Trending Software Industries Technologies.
ReplyDeletePython Course in Bangalore | Python Training in Bangalore
Machine Learning Training in Bangalore | Machine Learning Course in Bangalore
AWS Training in Bangalore | AWS course in Bangalore
AngularJS Training in Bangalore | AngularJS Course in Bangalore
Data Science Course in Bangalore | Data Science Training in Bangalore
Selenium course in bangalore | Selenium Training in Bangalore
Java Training in Bangalore | Java Course in Bangalore
Core Java Training in Bangalore | Core Java Course in Bangalore
Android Training in Bangalore | Android course in Bangalore
Data Science with Python Training in Bangalore | Data Science with Python Course in Bangalore
Machine Learning with Python Training in Bangalore | Machine Learning with Python Course in Bangalore
Best ambulance service in Patna
ReplyDelete