SQL Clone
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 (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)SSC-Enthusiastic (197 reputation)

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

Group: General Forum Members
Points: 41 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
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3218 Visits: 3854
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
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4622 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
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3218 Visits: 3854
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
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4622 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 (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 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
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2712 Visits: 1737
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 (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 36
Thanks a lot for the script a rather easy and better way to do the job. :-)
Iwas Bornready
Iwas Bornready
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38642 Visits: 886
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