Delete duplicate rows from the table using row_number()

  • Comments posted to this topic are about the item Delete duplicate rows from the table using row_number()

  • 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!

  • 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

  • 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.

  • 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

  • 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.

  • 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.

  • 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

  • Thanks a lot for the script a rather easy and better way to do the job. 🙂

  • Thanks for the script.

  • umairjavedsheikh (4/18/2012)


    Thanks a lot for the script a rather easy and better way to do the job. 🙂

    Totally agree.

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply