Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Delete duplicate rows from the table using row_number() Expand / Collapse
Author
Message
Posted Monday, September 6, 2010 10:56 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, June 24, 2013 3:03 AM
Points: 193, Visits: 58
Comments posted to this topic are about the item Delete duplicate rows from the table using row_number()
Post #981306
Posted Tuesday, September 7, 2010 12:56 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, July 4, 2011 6:16 AM
Points: 15, 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!
Post #981362
Posted Tuesday, July 5, 2011 9:02 AM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, July 14, 2014 10:08 AM
Points: 754, Visits: 3,816
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
Post #1136546
Posted Tuesday, July 5, 2011 1:18 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,232, Visits: 1,046
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.
Post #1136771
Posted Tuesday, July 5, 2011 1:26 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, July 14, 2014 10:08 AM
Points: 754, Visits: 3,816
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
Post #1136778
Posted Tuesday, July 5, 2011 1:52 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 31, 2013 8:01 AM
Points: 1,232, Visits: 1,046
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.
Post #1136794
Posted Tuesday, July 5, 2011 4:37 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, August 23, 2013 1:56 PM
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.
Post #1136915
Posted Tuesday, December 20, 2011 1:07 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, August 25, 2014 3:02 PM
Points: 323, Visits: 1,459
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.

Ken
Post #1224726
Posted Wednesday, April 18, 2012 6:06 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 17, 2013 5:49 AM
Points: 2, Visits: 36
Thanks a lot for the script a rather easy and better way to do the job.
Post #1285579
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse