How to delete the duplicate data in between two distinct rows in SQL?

Hi,
I need to identify the duplicate data with two distinct rows. See my data structure below.
NAME NAME_1 VALUE START_DATE END_DATE FLAG INDEX
SUR SE 275 13/12/2005 31/12/2010 B 1
SUR SE 375 A 1
SUR SE 475 A 1
SUR SE 275 13/12/2005 31/12/2010 B 2
SUR SE 375 A 2
SUR SE 475 A 2
SUR SE 175 13/12/2006 31/12/2010 B 3
SUR SE 375 A 3
SUR SE 475 A 3
This is my sample data. Here data are duplicate with different index columns. INDEX 1 and 2 contains same group of combination. So i need to identify any one of duplicate combination(i.e INDEX 1 or 2). Can anyone come up with exact solution?
Thanks

Try this:
with test_table as
(select 'SUR' NAME, 'SE' NAME_1, 275 VALUE, '13/12/2005' START_DATE, '31/12/2010' END_DATE, 'B' FLAG, 1 IND from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 1 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 1 from dual union all
select 'SUR', 'SE', 275, '13/12/2005' ,'31/12/2010' ,'B', 2 from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 2 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 2 from dual union all
select 'SUR', 'SE', 175, '13/12/2006', '31/12/2010', 'B', 3 from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 3 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 3 from dual )
select t.*,
       CASE WHEN START_DATE IS NULL THEN
         first_value(row_number) OVER (PARTITION BY NAME, NAME_1, IND ORDER BY START_DATE)
       ELSE
         row_number
       END row_number
from (
SELECT t.*,
       CASE WHEN START_DATE IS NOT NULL THEN
         row_number() over(PARTITION BY NAME, NAME_1,VALUE, START_DATE, END_DATE, FLAG
                           ORDER BY IND)
       END row_number
  FROM test_table t) t
order by IND, start_dateNote that this is only checking for diferences in the rows where start_date is not null. Do you want to also check if the records where start_date is null it there are differences? If so you can do this:
with test_table as
(select 'SUR' NAME, 'SE' NAME_1, 275 VALUE, '13/12/2005' START_DATE, '31/12/2010' END_DATE, 'B' FLAG, 1 IND from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 1 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 1 from dual union all
select 'SUR', 'SE', 275, '13/12/2005' ,'31/12/2010' ,'B', 2 from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 2 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 2 from dual union all
select 'SUR', 'SE', 175, '13/12/2006', '31/12/2010', 'B', 3 from dual union all
select 'SUR', 'SE', 375, null, null, 'A', 3 from dual union all
select 'SUR', 'SE', 475, null, null, 'A', 3 from dual )
SELECT t.*,
       MIN(row_number) OVER(PARTITION BY NAME, NAME_1, IND) MIN
  FROM (SELECT t.*,
               row_number() over(PARTITION BY NAME, NAME_1, VALUE,
                                              START_DATE, END_DATE, FLAG
                                     ORDER BY IND) row_number
          FROM test_table t) t
ORDER BY IND,
          start_date;Edited by: Manuel Vidigal on 13/Abr/2009 12:05

Similar Messages

  • How to delete the duplicate data  from PSA Table

    Dear All,
    How to delete the duplicate data  from PSA Table, I have the purchase cube and I am getting the data from Item data source.
    In PSA table, I found the some cancellation records for that particular records quantity  would be negative for the same record value would be positive.
    Due to this reason the quantity is updated to target but the values would summarized and got  the summarized value  of all normal and cancellation .
    Please let me know the solution how to delete the data while updating to the target.
    Thanks
    Regards,
    Sai

    Hi,
    in deleting the records in PSA table difficult and how many you will the delete.
    you can achieve the different ways.
    1. creating the DSO maintain the some key fields it will overwrite the based on key fields.
    2. you can write the ABAP logic deleting the duplicate records at info package level check with the your ABAPer.
    3.you can restrict the cancellation records at query level.
    Thanks,
    Phani.

  • How to delete the duplicate email address in BP master data

    Hi,
    When  you get an email ids from the third party vendor and you are loading into CRM BP master data.  how to delete the duplicate email address already exits in the system.  In CRM you can create the same BP with different id.   I would like to know how to delete the email address during importing email addresses from the third party tool.
    During the campaign you are sending email to all your customers, when the customer want to unsubscibe the email address from your list, how to unsubcribe the email address and how to updat the BP master data. 
    If you are sending the email to customer, you are using html or simple text, if the customer wants only html or simple text, how you to specify in the system?
    thanks,
    arul

    Hello Arul,
    welcome to the SDN CRM Development forum.
    1. I think you should clear the data with duplicate E-Mail adresses in the external tool.
    2. Unsubscription could be done by a Marketing Attribute which could be set by using a Target Group which is created by Campaign Automation. Have a look at this Toppic. There is also a Best Practice avaliable at http://help.sap.com/bp_crmv340/CRM_DE/index.htm.
    3. Also HTML or Simple text can be mained in a Marketing Attribute. You have to use different Mail Forms to which are sent to different Target groups.
    Regards
    Gregor

  • HT2905 Most all of my 1700 songs have been duplicated in iTunes. I have downloaded the instructions how to delete the duplicates but it says "sort by the date you added" and i have no column that says that. I am running windows xp.

    Most all of my 1700 songs have been duplicated in iTunes. I have downloaded the instructions how to delete the duplicates but it says "sort by the date you added" and i have no column that says that. I am running windows xp.

    Apple's official advice is here... HT2905 - How to find and remove duplicate items in your iTunes library. It is a manual process and the article fails to explain some of the potential pitfalls.
    Use Shift > View > Show Exact Duplicate Items to display duplicates as this is normally a more useful selection. You need to manually select all but one of each group to remove. Sorting the list by Date Added may make it easier to select the appropriate tracks, however this works best when performed immediately after the dupes have been created.  If you have multiple entries in iTunes connected to the same file on the hard drive then don't send to the recycle bin.
    Use my DeDuper script if you're not sure, don't want to do it by hand, or want to preserve ratings, play counts and playlist membership. See this thread for background and please take note of the warning to backup your library before deduping.
    (If you don't see the menu bar press ALT to show it temporarily or CTRL+B to keep it displayed)
    tt2

  • How to delete the duplicate requests in a cube after compression.

    Hi experts,
        1. How to delete the duplicate requests in a cube after compression.?
        2. How to show a charaterstics and a keyfigure side by side in a bex query output?
    Regards,
    Nishuv.

    Hi,
    You cannot delete the request as its compressed as all the data would have been moved to E table ..
    If you have the double records you may use the selective deletion .
    Check this thread ..
    How to delete duplicate data from compressed requests?
    Regards,
    shikha

  • How to delete the duplicate cards in ALUI

    Hi,
    How to delete the duplicate cards in knowledge directory
    Thanks & Regards
    Dheeraj
    Edited by: dheeraj on Sep 17, 2008 2:31 PM

    Not sure if there is an automated way to do this, but I get around it by just searching on (2), (3), (4).
    Not practical for large installs, but it works in our small environment.
    You might be able to use the Smart Sort utility to find files that have () characters in them? Not positive though.
    It would make a great enhancement request to add dupes to either a log file or better yet an admin utility to track the living documents to ensure they are fixed!
    (I'm going to file such an enhancement right now!)

  • How to delete the duplicate cards in alui crawlers

    How to delete the duplicate cards in alui crawlers

    Not sure if there is an automated way to do this, but I get around it by just searching on (2), (3), (4).
    Not practical for large installs, but it works in our small environment.
    You might be able to use the Smart Sort utility to find files that have () characters in them? Not positive though.
    It would make a great enhancement request to add dupes to either a log file or better yet an admin utility to track the living documents to ensure they are fixed!
    (I'm going to file such an enhancement right now!)

  • How to delete the Hierarchy data from Infoobjects.

    How to delete the Hierarchy data from Infoobjects. In my case I had 300 records in the corresponding table of info object.
    When i was trying to delete the hierarchy data, I am getting error message. "Some master data not deleted". Can any one tell me to delete all these records by using a program.

    Hi
    Go to SE11 and enter the hierarchy table name.
    /BIC/H....(infoobject name)...and execute the table and select table entry and delete all....
    Thanks
    TG

  • How to identify the follow up relationship between two service ticket

    Hi Folks,
    How to identify the follow up relationship between two service ticket ?
    Please help me on this...
    Regards,
    Shashi K, Reddy

    Hi Pepe !
    Thank you for the answer, but I dont find this structure ET_DOC_FLOW.....
    Please let me know is that structure is correct ......
    Regards,
    Shashi K, Reddy
    shashikumarreddy at gmail dot com

  • How to delete the Transaction Data in CRM

    Hi Gurus,
    I have a requirement to delete the Transaction Data in one Client.
    But Configuration should be as it is ?
    How can i over come this situation?

    HI.
    Do you mean refresh the client ? if that is the case, i think you are posting in wrong forum since this one is for People Centric User Interface. Try in   Customer "Relationship Management (CRM) - General & Framework".
    Best Regards.
    Armando Rodriguez.

  • How to calculate the no. of weekdays between two active dates

    Hi all,
    I need to calculate the no. of weekdays between two days.
    For Example:
    If i want to know the number of weekdays between 17-NOV-2008 to 7-DEC-2008 its 10 excluding sat and sun.
    how to do that if the period is more?
    like 1-JAN-2006 to 12-APR-2007
    Thanks in advance..
    Regards,
    Manoj

    NEXT_DAY(start_date - 1,'SUNDAY') is first sunday >= start_date. NEXT_DAY(end_date - 7,'SUNDAY') is last Sunday <= end_date. Therefore:
    (NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 + 1 is number of Sunday's between start_date and end_date. Same way:
    (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 + 1 As a result, number of weekdays between start_date and end_date is:
    business_day_count := end_date - start_date + 1 -((NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 + 1 + (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 + 1) or
    business_day_count := end_date - start_date - 1 -(NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 - (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 or:
    SELECT end_date - start_date - 1 -(NEXT_DAY(end_date - 7,'SUNDAY') - NEXT_DAY(start_date - 1,'SUNDAY')) / 7 - (NEXT_DAY(end_date - 7,'SATURDAY') - NEXT_DAY(start_date - 1,'SATURDAY')) / 7 FROM DUAL; The above code assumes business day count between two dates includes both start and end dates. Keep in mind, the above code is NLS dependent.
    SY.

  • How to delete the duplicate records in a table without promary key

    I have a table that contains around 1 million records and there is no promary key or auto number coulums. I need to delete the duplicate records from this table. what is the simple effective way to do this.

    Please see this link:
    Remove duplicate records ...
    sqldevelop.wordpress.com

  • How to Delete the Junk data in Transformation Routines

    Hi,
    I had scenario like infoobject for 0CUSTOMER master data is bringing the values
    C123456_RECEIPTS.
    C12345_RECEIPTS.
    So when i extract the data from R/3 for this 0CUSTOMER master data it is bringing the SOME JUNK DATA
    I would require delete the C12345_RECIEPTS it should allow only C123456_RECIEPTS.
    I have to do in the routines for the deletion of this.
    Requesting send some sample code on how to delete it the BI 7.

    Hello,
    If the data is like after every C5* or C6* there is an underscroll sign (_), then below code will work in start routine:
    Data: wa_source_package like line of source_package,
              itab_sp type standard table of tys_SC_1,
              a(6) type c,
              b(10) type c.
    loop at source_package into wa_source_package.
       split wa_source_package at '_' into a and b.
       if strlen( a ) = 7.
          append wa_source_package to itab_sp.
       endif.
    endloop.
    refresh source_package.
    source_package = itab_sp.
    Regards,
    Shashank

  • How to delete the populated data in the control screen of XK02 transaction

    In the vendor master ( XK01/2/3)  "Control screen " we have some user defined fields with data already populated into those fields. Now, the user is asking to delete the data which is already populated for a particular purchaging Organization. How to do that.
    Ur help wil be highly appreciated.

    Hello,
    If the data is like after every C5* or C6* there is an underscroll sign (_), then below code will work in start routine:
    Data: wa_source_package like line of source_package,
              itab_sp type standard table of tys_SC_1,
              a(6) type c,
              b(10) type c.
    loop at source_package into wa_source_package.
       split wa_source_package at '_' into a and b.
       if strlen( a ) = 7.
          append wa_source_package to itab_sp.
       endif.
    endloop.
    refresh source_package.
    source_package = itab_sp.
    Regards,
    Shashank

  • How to delete the master data of a Customer created in a SALES AREA?

    Hi All,
    I've deleted a Customer (master data) by t.code OBR2. But it exists again in its SALES AREA.
    Could anyone tell me how to delete it in the sales area too?
    Thanks

    Hi,
    I dont think you can delete a customer. you can market it for deletion in XD06.
    for deleting customer master data you have to setup an archiving project.
    Also check the similar thread
    doubt in obr2
    Hope it helps you.
    Regards,
    Sats.

Maybe you are looking for