Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Delete duplicate rows from the table using row_number()


Delete duplicate rows from the table using row_number()

Author
Message
rajesh_friends2005
rajesh_friends2005
SSC-Enthusiastic
SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)

Group: General Forum Members
Points: 195 Visits: 59
Comments posted to this topic are about the item Delete duplicate rows from the table using row_number()
crackbridge
crackbridge
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 48
It's actually cool. Thanks a lot. Have you test it for large tables, with joins?

I have recently checked it uses to be faster sometimes to create the temporal table (t) instead of using that feature you have used, specially when further joins are going to be declared linking the "temporal" table created on the fly in this case inside parenthesis ()t.

Have a good day!
mtillman-921105
mtillman-921105
SSChasing Mays
SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)

Group: General Forum Members
Points: 634 Visits: 3852
Very good! Thank you.

It surprises me that the DELETE statement works because I would have thought that the table would have to be explicitly named, but it works nevertheless.

______________________________________________________________________
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
SanDroid
SanDroid
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1414 Visits: 1046
This was done in a single script, but not a single query.

The insert into the #temp table is executed as a seperate query.

You would need to start with the use of a WITH table statement, or a derived table to get this done to a single query.

Interesting way to resolve a bad table design issue without correcting the bad table design.
mtillman-921105
mtillman-921105
SSChasing Mays
SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)SSChasing Mays (634 reputation)

Group: General Forum Members
Points: 634 Visits: 3852
SanDroid (7/5/2011)
This was done in a single script, but not a single query.

The insert into the #temp table is executed as a sperate query.

You would need to start with the use of a WITH table statement, or a derived table to get this done to a single query.

Interesting way to resolve a bad table design issue without correcting the bad table design.


At times you have to work with less than perfect data even if it's no fault of your own.

Also, in my estimation, the "single query" push is a little overrated. What's the advantage of a single query? Performance can be enhanced in some cases with more than one query. So performance itself can't always be the answer.

______________________________________________________________________
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
SanDroid
SanDroid
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1414 Visits: 1046
mtillman-921105 (7/5/2011)
SanDroid (7/5/2011)
This was done in a single script, but not a single query.

The insert into the #temp table is executed as a sperate query.

You would need to start with the use of a WITH table statement, or a derived table to get this done to a single query.

Interesting way to resolve a bad table design issue without correcting the bad table design.


At times you have to work with less than perfect data even if it's no fault of your own.

Also, in my estimation, the "single query" push is a little overrated. What's the advantage of a single query? Performance can be enhanced in some cases with more than one query. So performance itself can't always be the answer.


The name of the article compared to it's syntax and content inspired the entire post.
Please do not confuse my comments on the authors odd word choice in this article as a personal opinion on some subject that was not mentioned.
don 24688
don 24688
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 77
SanDroid (7/5/2011)
This was done in a single script, but not a single query.

The insert into the #temp table is executed as a seperate query.

You would need to start with the use of a WITH table statement, or a derived table to get this done to a single query.

Interesting way to resolve a bad table design issue without correcting the bad table design.

Maybe I'm wrong, but I think all of the #temp table stuff was just to have sample data to show how the technique works. He could have just written something like:
Delete T From
(Select Row_Number() Over(Partition By [fld1],[fld2],[fld3],[fld4] order By [fld1]) As RowNumber,* From [tablename])T
Where T.RowNumber > 1



and then explained that the partition clause needs to include all of the fields. Instead, he included a concrete example.
ken.trock
ken.trock
Old Hand
Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)

Group: General Forum Members
Points: 392 Visits: 1713
Yeah, it's cool; I didn't know you could do this. I was getting this type of thing done by, and I'll use the C word, a cursor. :-D

Ken
umairjavedsheikh
umairjavedsheikh
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 36
Thanks a lot for the script a rather easy and better way to do the job. :-)
Iwas Bornready
Iwas Bornready
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8680 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search