Page 14 of 20 FirstFirst ... 41213141516 ... LastLast
Results 131 to 140 of 197

Thread: IT Professionals

  1. #131
    Senior Member Diamond Hubber PARAMASHIVAN's Avatar
    Join Date
    May 2009
    Location
    Kailash
    Posts
    5,541
    Post Thanks / Like
    App_engine anna and others

    Has any one used the 'RANK' function in SQL Serever 2005/ 2008 or even in Oracle 8i to identify duplicate records ?
    Om Namaste astu Bhagavan Vishveshvaraya Mahadevaya Triambakaya Tripurantakaya Trikalagni kalaya kalagnirudraya Neelakanthaya Mrutyunjayaya Sarveshvaraya Sadashivaya Shriman Mahadevaya Namah Om Namah Shivaye Om Om Namah Shivaye Om Om Namah Shivaye

  2. # ADS
    Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many
     

  3. #132
    Senior Member Platinum Hubber
    Join Date
    Oct 2004
    Posts
    10,586
    Post Thanks / Like
    Param,
    By duplicate if you mean only some fields (and not the entire row), then using the analytic function RANK is a very standard practice in Oracle.

    e.g. many people with the same first name / last name, like "John Anderson" but different emplid's or SSNs are "duplicate" in the "name-sense" and you can use the analytic function to pick one and get rid of others.

    However, if the purpose is for deleting two "identical" rows (no unique constraint defined for the table), RANK won't work.

    The earlier case is nicely explained here :
    http://www.devx.com/getHelpOn/10Minu...ion/16597/1954
    A SQL Solution: Deleting Duplicate Data with a Single SQL Statement Using RANK()
    The Oracle 8i analytic function RANK() allows you to rank each item in a group.

    In our case, we are using this function to assign dynamically sequential numbers in the group of duplicates sorted by the primary key. With RANK(), grouping is specified in the PARTITION BY clause and sort order for ranking is specified in the ORDER BY clause:

    SELECT ID, LastName, FirstName,
    RANK() OVER (PARTITION BY LastName,
    FirstName ORDER BY ID) SeqNumber
    FROM Customers
    ORDER BY LastName, FirstName;

    Bingo! Now, values in the SeqNumber column, assigned by RANK(), allow you to separate all duplicate rows (SeqNumber > 1) from non-duplicates (SeqNumber = 1) and retrieve only those rows you want to delete:

    SELECT ID, LastName, FirstName
    FROM
    (SELECT ID, LastName, FirstName,
    RANK() OVER (PARTITION BY LastName,
    FirstName ORDER BY ID) AS SeqNumber
    FROM Customers)
    WHERE SeqNumber > 1;

  4. #133
    Senior Member Senior Hubber kirukan's Avatar
    Join Date
    Nov 2004
    Location
    udal koodu
    Posts
    600
    Post Thanks / Like
    Quote Originally Posted by PARAMASHIVAN
    App_engine anna and others

    Has any one used the 'RANK' function in SQL Serever 2005/ 2008 or even in Oracle 8i to identify duplicate records ?
    If you wanna delete duplicate rows then the technique we used earlier was creating a temp table identical to the table.insert distinct data into the temp table from the original and then move the same back to original.

    insert into @temp select distinct col1,col2,col3 from mytable
    delete mytable
    insert into mystable select col1,col2,col3 from @temp

    -
    கிறுக்கன்

  5. #134
    Senior Member Diamond Hubber PARAMASHIVAN's Avatar
    Join Date
    May 2009
    Location
    Kailash
    Posts
    5,541
    Post Thanks / Like
    test test test
    Om Namaste astu Bhagavan Vishveshvaraya Mahadevaya Triambakaya Tripurantakaya Trikalagni kalaya kalagnirudraya Neelakanthaya Mrutyunjayaya Sarveshvaraya Sadashivaya Shriman Mahadevaya Namah Om Namah Shivaye Om Om Namah Shivaye Om Om Namah Shivaye

  6. #135
    Senior Member Diamond Hubber PARAMASHIVAN's Avatar
    Join Date
    May 2009
    Location
    Kailash
    Posts
    5,541
    Post Thanks / Like
    Thanks Kirukukan and App na , I will try that. BTW, I have question , how do you find the second highest value or 3rd highest value in a column, say you have vcolumn called salary, so ' Select Max(salary) from table' would return the highest salary, but how about the second or thir highest ?
    Om Namaste astu Bhagavan Vishveshvaraya Mahadevaya Triambakaya Tripurantakaya Trikalagni kalaya kalagnirudraya Neelakanthaya Mrutyunjayaya Sarveshvaraya Sadashivaya Shriman Mahadevaya Namah Om Namah Shivaye Om Om Namah Shivaye Om Om Namah Shivaye

  7. #136
    Senior Member Platinum Hubber
    Join Date
    Oct 2004
    Posts
    10,586
    Post Thanks / Like
    One technique in Oracle is by using rownum / order by

    e.g.

    select * from
    (select rownum r, CR
    from
    (select distinct comprate CR
    from ps_compensation
    order by comprate)
    )
    where r = 2

  8. #137
    Senior Member Platinum Hubber
    Join Date
    Oct 2004
    Posts
    10,586
    Post Thanks / Like
    The above sql will get the 2nd lowest

    For highest, your order by should add "desc".

  9. #138
    Senior Member Diamond Hubber PARAMASHIVAN's Avatar
    Join Date
    May 2009
    Location
    Kailash
    Posts
    5,541
    Post Thanks / Like
    Thanks app Na

    but would the above script work in SQL Server?
    Om Namaste astu Bhagavan Vishveshvaraya Mahadevaya Triambakaya Tripurantakaya Trikalagni kalaya kalagnirudraya Neelakanthaya Mrutyunjayaya Sarveshvaraya Sadashivaya Shriman Mahadevaya Namah Om Namah Shivaye Om Om Namah Shivaye Om Om Namah Shivaye

  10. #139
    Senior Member Platinum Hubber
    Join Date
    Oct 2004
    Posts
    10,586
    Post Thanks / Like
    It had been years since I used a sql server database. Possibly in 2002...been in all-oracle world since then.

    Try it out

  11. #140
    Senior Member Diamond Hubber PARAMASHIVAN's Avatar
    Join Date
    May 2009
    Location
    Kailash
    Posts
    5,541
    Post Thanks / Like
    Thanks App annEh
    Om Namaste astu Bhagavan Vishveshvaraya Mahadevaya Triambakaya Tripurantakaya Trikalagni kalaya kalagnirudraya Neelakanthaya Mrutyunjayaya Sarveshvaraya Sadashivaya Shriman Mahadevaya Namah Om Namah Shivaye Om Om Namah Shivaye Om Om Namah Shivaye

Page 14 of 20 FirstFirst ... 41213141516 ... LastLast

Similar Threads

  1. IT Professionals
    By Raghu in forum Miscellaneous Topics
    Replies: 206
    Last Post: 19th July 2007, 09:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •