Deleting Duplicate records ::(Please reply to it ::)

Hi experts i am new to the oracle .Please me with this delete query .
When ever the mobileno in TEST_REG,TEST_MUL matches then it has to check for accountno gets duplicated in TEST_MUL table .
If duplicate accounts are there for that particular mobileno
Then it has to delete that duplicate accountno whose ids are not equal in both the
tables (those accountno records should get deleted from test_mul table)
Script For the query :
create table test_mul (mobileno VARCHAR2 (20 Byte),accountno VARCHAR2 (20 Byte),id VARCHAR2 (12 Byte),v_date date);
create table test_reg (mobileno VARCHAR2 (20 Byte),id VARCHAR2 (12 Byte),r_date date,mas varchar2(1) default 'Y');
alter table test_mul modify v_date default sysdate;
alter table test_reg modify r_date default sysdate;
Insertion of records into test_reg table :
insert into test_reg (mobileno,id) values ('+227299001081','AAA');
insert into test_reg (mobileno,id) values ('+911000000001','BBB');
insert into test_reg (mobileno,id) values ('+911000000002','CCC');
insert into test_reg (mobileno,id) values ('+911000000005','DDD');
insert into test_reg (mobileno,id) values ('+911000000006','EEE');
insert into test_reg (mobileno,id) values ('+911000000007','FFF');
commit;
==================================================================
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+227299001081','37775521122561','AAA');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+227299001081','37775521122561','123');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+227299001081','43443345432344','AAA');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+227299001081','43443345432344','AAA');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000001','08490100005169','BBB');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000001','08490100006867','BBB');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000001','08490100009602','BBB');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000001','08490100009602','456');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000005','47775524511505','DDD');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000002','47775521111505','DDD');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000002','47775524511505','789');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000006','47775545611506','EEE');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000006','47775521111506','EEE');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000007','47987521111507','FFF');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000007','47775521111507','FFF');
INSERT INTO TEST_MUL(mobileno,accountno,id) VALUES ('+911000000007','47775521111507','987');
commit;Edited by: 980560 on Jan 26, 2013 7:56 PM

Something like this?
Go through the complete workout :
Ranit>> select *
  2  from
  3       test_mul;
MOBILENO             ACCOUNTNO            ID           V_DATE                                                                                                                                                              
+227299001081        37775521122561       AAA          26-JAN-13                                                                                                                                                           
+227299001081        37775521122561       123          26-JAN-13                                                                                                                                                           
+227299001081        43443345432344       AAA          26-JAN-13                                                                                                                                                           
+227299001081        43443345432344       AAA          26-JAN-13                                                                                                                                                           
+911000000001        08490100005169       BBB          26-JAN-13                                                                                                                                                           
+911000000001        08490100006867       BBB          26-JAN-13                                                                                                                                                           
+911000000001        08490100009602       BBB          26-JAN-13                                                                                                                                                           
+911000000001        08490100009602       456          26-JAN-13                                                                                                                                                           
+911000000005        47775524511505       DDD          26-JAN-13                                                                                                                                                           
+911000000002        47775521111505       DDD          26-JAN-13                                                                                                                                                           
+911000000002        47775524511505       789          26-JAN-13                                                                                                                                                           
+911000000006        47775545611506       EEE          26-JAN-13                                                                                                                                                           
+911000000006        47775521111506       EEE          26-JAN-13                                                                                                                                                           
+911000000007        47987521111507       FFF          26-JAN-13                                                                                                                                                           
+911000000007        47775521111507       FFF          26-JAN-13                                                                                                                                                           
+911000000007        47775521111507       987          26-JAN-13                                                                                                                                                           
16 rows selected.
Ranit>> select *
  2  from
  3       test_reg;
MOBILENO             ID           R_DATE    M                                                                                                                                                                              
+227299001081        AAA          26-JAN-13 Y                                                                                                                                                                              
+911000000001        BBB          26-JAN-13 Y                                                                                                                                                                              
+911000000002        CCC          26-JAN-13 Y                                                                                                                                                                              
+911000000005        DDD          26-JAN-13 Y                                                                                                                                                                              
+911000000006        EEE          26-JAN-13 Y                                                                                                                                                                              
+911000000007        FFF          26-JAN-13 Y                                                                                                                                                                              
6 rows selected.
Ranit>> select m.*
  2  from
  3       test_reg r, test_mul m
  4  where
  5       r.mobileno = m.mobileno
  6  and
  7       r.id != m.id;
MOBILENO             ACCOUNTNO            ID           V_DATE                                                                                                                                                              
+227299001081        37775521122561       123          26-JAN-13                                                                                                                                                           
+911000000001        08490100009602       456          26-JAN-13                                                                                                                                                           
+911000000002        47775521111505       DDD          26-JAN-13                                                                                                                                                           
+911000000002        47775524511505       789          26-JAN-13                                                                                                                                                           
+911000000007        47775521111507       987          26-JAN-13                                                                                                                                                           
Ranit>> delete from test_mul m
  2  where (mobileno,id) != (
  3  select r.mobileno,r.id
  4  from
  5       test_reg r
  6  where
  7       r.mobileno = m.mobileno
  8  and
  9       r.id != m.id
10  );
5 rows deleted.
Ranit>> select *
  2  from
  3  test_mul;
MOBILENO             ACCOUNTNO            ID           V_DATE                                                                                                                                                              
+227299001081        37775521122561       AAA          26-JAN-13                                                                                                                                                           
+227299001081        43443345432344       AAA          26-JAN-13                                                                                                                                                           
+227299001081        43443345432344       AAA          26-JAN-13                                                                                                                                                           
+911000000001        08490100005169       BBB          26-JAN-13                                                                                                                                                           
+911000000001        08490100006867       BBB          26-JAN-13                                                                                                                                                           
+911000000001        08490100009602       BBB          26-JAN-13                                                                                                                                                           
+911000000005        47775524511505       DDD          26-JAN-13                                                                                                                                                           
+911000000006        47775545611506       EEE          26-JAN-13                                                                                                                                                           
+911000000006        47775521111506       EEE          26-JAN-13                                                                                                                                                           
+911000000007        47987521111507       FFF          26-JAN-13                                                                                                                                                           
+911000000007        47775521111507       FFF          26-JAN-13                                                                                                                                                           
11 rows selected.Please let us know if this helps and meets your requirement.

Similar Messages

  • Delete duplicate records

    Hi everyone,
    I am writing a statement to delete duplicate records in my data.
    For example:
    select identnr,datum,klokin,klokuit,count(datum)
    from fus_timesheets
    group by identnr,datum,klokin,klokuit
    having count(datum) > 1; Above code gives following result:
    IDENTNR                DATUM                     KLOKIN     KLOKUIT    COUNT(DATUM)          
    10376                  14/09/2009                                                     2                     
    10376                  16/09/2009                                                     3                     
    10376                  15/09/2009                                                    16    What i want to do is delete duplicate records, meaning that count(datum) will have a value of 1.
    I have written following code to delete duplicate records :
    declare
    type tst_type is record
        (identnr number
        ,datum varchar2(15)
        ,klokin varchar2(10)
        ,klokuit varchar2(10)
        ,aantal  number(3));
        type type_coll_tst
        is table of tst_type;
        t_tst type_coll_tst;
    begin
    select identnr,datum,klokin,klokuit,count(datum)
    bulk collect into t_tst
    from fus_timesheets
    group by identnr,datum,klokin,klokuit
    having count(datum) > 1;
    for i in 1..t_tst.count loop
    dbms_output.put_line(t_tst(i).identnr ||' '|| t_tst(i).datum||' '||t_tst(i).aantal);
    end loop;
    for i in 1..t_tst.count loop
    delete from fus_timesheets
    where identnr = t_tst(i).identnr
    and klokin = t_tst(i).klokin
    and klokuit = t_tst(i).klokuit
    and datum = t_tst(i).datum
    and rownum < t_tst(i).aantal;
    end loop;
    end;My delete statement is not working good.
    Can someone please help me with the delete part?
    Thanks,
    Diana

    Manage correctly null values:
    for i in 1..t_tst.count loop
    delete from fus_timesheets
    where identnr = t_tst(i).identnr
    and (klokin = t_tst(i).klokin or (t_tst(i).klokin is null and klokin is null))
    and (klokuit = t_tst(i).klokuit or (t_tst(i).klokuit is null and klokuit is null))
    and datum = t_tst(i).datum
    and rownum < t_tst(i).aantal;
    end loop;Max

  • How to delete duplicate records in 10 G.

    how to delete duplicate records in 10 G.

    --Here is one way to do it using a second table 
    create table temp1
    (col1 char(1));
    --Table created.
    insert into temp1 (col1) values('A');
    insert into temp1 (col1) values('B');
    insert into temp1 (col1) values('B');
    --1 row created.
    --1 row created.
    --1 row created.
    create table temp2 as select distinct * from temp1;
    --Table created.
    --now you have a second table with no duplicates
    --truncate your old table
    truncate table temp1;
    --Table truncated.
    --and reload it with data from the new table
    insert into temp1 select * from temp2;
    --2 rows created.
    --then drop the temp2 table
    drop table temp2

  • Deleting duplicate records

    Hi,
    Can I know is there any way to delete the duplicate recors in the internal table?
    The code i'm using seem not working.Thanks.
    SELECT *
      INTO CORRESPONDING FIELDS
        OF TABLE  i_pa0009
         FROM pa0001 INNER JOIN pa0009
        ON pa0001pernr = pa0009pernr
        WHERE bukrs IN s_ccode AND
         bankn NE ''.
    DELETE ADJACENT DUPLICATES FROM i_pa0009 COMPARING ALL FIELDS .
    or
    How can I move the company code to the i_PA0009 table with all i_PA0009 data?
    SELECT bukrs pernr INTO TABLE i_tmp
      FROM pa0001
      WHERE bukrs IN s_ccode.
      IF NOT i_tmp[] IS INITIAL.
        DELETE ADJACENT DUPLICATES FROM i_comp.
        SELECT * INTO CORRESPONDING FIELDS OF TABLE i_pa0009
        FROM pa0009
        FOR ALL ENTRIES IN i_tmp
        WHERE pernr EQ i_tmp-pernr AND
            bankn NE ''.
    endif.

    Hi,
    Yes, I would like to delete duplicate records in i_PA0009.
    But It seem it not successful to delete all as I saw there's still remain duplicate records during the debugging.
    Below here is the code i tried.
    SELECT *
       INTO CORRESPONDING FIELDS
         OF TABLE  i_p0009
         FROM pa0001 INNER JOIN pa0009
         ON pa0001pernr = pa0009pernr
         WHERE bukrs IN s_ccode AND
         bankn NE space.
      SORT i_p0009 BY pernr.
      DELETE ADJACENT DUPLICATES FROM i_p0009 COMPARING pernr endda begda.
    Second approach.  Could anyone advise on below how i can move the bukrs from i_tmp to the i_PA0009 table with the i_PA0009 data as well.
    SELECT bukrs pernr INTO TABLE i_tmp
    FROM pa0001
    WHERE bukrs IN s_ccode.
    IF NOT i_tmp[] IS INITIAL.
    DELETE ADJACENT DUPLICATES FROM i_comp.
    SELECT * INTO CORRESPONDING FIELDS OF TABLE i_pa0009
    FROM pa0009
    FOR ALL ENTRIES IN i_tmp
    WHERE pernr EQ i_tmp-pernr AND
    bankn NE space.
    endif.
    Edited by: Blue Sky on Feb 27, 2009 11:23 AM

  • Deleting Duplicate Records -EIM  Import Account & Contact

    Hi,
    Can anyone give me the query to delete duplicate records both from legacy as well as from the tables imported.

    Try this..
    DELETE
    FROM table
    WHERE ROWID NOT IN(SELECT MAX(ROWID)
    FROM table
    GROUP BY column)
    For which column u have duplicate rows that column u have to give in group by clause so except max of rowid it will delete all records.

  • Delete Duplicate Record leaving  1 record

    Hi friends
    I want to delete a record from table where there is duplicate which i am able to do it , but i want while deleting it should leave 1 record.
    for ex
    1111
    1111
    2222
    2222
    it should delete all duplicate and leave the unique one.
    1111
    2222
    sandy

    Here are some ideas:
    AskTom: Deleting duplicate records
    AskTom: Deleting duplicate records without using rowid and rownum
    AskTom: to remove duplicate records

  • How to delete duplicate record in Query report

    Hi Experts,
    I had created an infoset and query in my sap, but I want to delete some duplicate records before the list out put.Please can we add some further codes in the Extras code to delete duplicates? And how do it? Would you please give me a simple brief.
    Joe

    Hi,
    You can try to restrict in the filter area in query designer with the values for characteristic which gives correct
    result.
    But still i would suggest that in the cube you keep not the duplicate records as this is not your requirement and giving
    you wrong result.
    So you can reload the correct records in the cube inorder to avoid such problems even in future.
    Regards,
    Amit

  • Delete duplicate records based on condition

    Hi Friends,
    I am scratching my head as how to select one record from a group of duplicate records based upon column condition.
    Let's say I have a table with following data :
    ID   START_DATE   END_DATE    ITEM_ID     MULT    RETAIL            |                      RETAIL / MULT
    1     10/17/2008   1/1/2009     83     3     7                 |                            2.3333
    2     10/17/2008   1/1/2009     83     2     4                 |                            2
    3     10/17/2008   1/1/2009     83     2     4                 |                            2
    4     10/31/2008   1/1/2009     89     3     6                 |                            2
    5     10/31/2008   1/1/2009     89     4     10                |                            2.5
    6     10/31/2008   1/1/2009     89     4     10                |                            2.5
    7     10/31/2008   1/1/2009     89     6     6                 |                            1
    8     10/17/2008   10/23/2008     124     3     6                 |                            2From the above records the rule to identify duplicates is based on START_DATE,+END_DATE+,+ITEM_ID+.
    Hence the duplicate sets are {1,2,3} and {4,5,6,7}.
    Now I want to keep one record from each duplicate set which has lowest value for retail/mult(retail divided by mult) and delete rest.
    So from the above table data, for duplicate set {1,2,3}, the min(retail/mult) is 2. But records 2 & 3 have same value i.e. 2
    In that case pick either of those records and delete the records 1,2 (or 3).
    All this while it was pretty straight forward for which I was using the below delete statement.
    DELETE FROM table_x a
          WHERE ROWID >
                   (SELECT MIN (ROWID)
                      FROM table_x b
                     WHERE a.ID = b.ID
                       AND a.start_date = b.start_date
                       AND a.end_date = b.end_date
                       AND a.item_id = b.item_id);Due to sudden requirement changes I need to change my SQL.
    So, experts please throw some light on how to get away from this hurdle.
    Thanks,
    Raj.

    Well, it was my mistake that I forgot to mention one more point in my earlier post.
    Sentinel,
    Your UPDATE perfectly works if I am updating only NEW_ID column.
    But I have to update the STATUS_ID as well for these duplicate records.
    ID   START_DATE   END_DATE    ITEM_ID     MULT    RETAIL    NEW_ID   STATUS_ID |   RETAIL / MULT
    1     10/17/2008   1/1/2009     83     3     7         2         1      |     2.3333
    2     10/17/2008   1/1/2009     83     2     4                                |     2
    3     10/17/2008   1/1/2009     83     2     4           2         1      |     2
    4     10/31/2008   1/1/2009     89     3     6           7         1      |     2
    5     10/31/2008   1/1/2009     89     4     10          7         1      |     2.5
    6     10/31/2008   1/1/2009     89     4     10          7         1      |     2.5
    7     10/31/2008   1/1/2009     89     6     6                            |     1
    8     10/17/2008   10/23/2008     124     3     6                            |     2So if I have to update the status_id then there must be a where clause in the update statement.
    WHERE ROW_NUM = 1
      AND t2.id != t1.id
      AND t2.START_DATE = t1.START_DATE
      AND t2.END_DATE = t1.END_DATE
      AND t2.ITEM_ID = t1.ITEM_IDInfact the entire where_ clause in the inner select statement must be in the update where clause, which makes it totally impossible as T2 is persistent only with in the first select statement.
    Any thoughts please ?
    I appreciate your efforts.
    Definitely this is a very good learning curve. In all my experience I was always writing straight forward Update statements but not like this one. Very interesting.
    Thanks,
    Raj.

  • How to delete Duplicate records in IT2006

    Dear Experts
    We have a situation like where we have duplicate records with same start and end dates in IT2006. This is because of the incorrect configuration which we have corrected now, but we need to do  a clean-up for the existing duplicate records. Any idea on how to clean it?  I ran report RPTKOK00 to find these duplicates but I could not delete the duplicate/inconsistenct record using report RPTBPC10 or HNZUPTC0, i Could only delete the deductions happened in the record.
    Is there any standard report/any other means of deleting the duplicate records created in IT2006?
    Thanks in advance for all your help.
    Regards
    Vignesh.

    You could probably use se16n to identify the duplicates and create the list of quotas to delete, and you could probably use t-code lsmw to write up a script to delete them, but be aware that you can't delete a Quota if it's been deducted from.
    You'd have to delete the Absence/Attendance first, then delete the Quota, then recreate the Absence/Attendance.

  • How to delete duplicate records in cube

    Hi,
    can u help me how to delete the duplicate records in my cube
    and tell me some predifined cubes and data sourcess for MM and SD modules

    Hi Anne,
    about "duplicate records" could you be more precise?.
    The must be at least one different Characteristic to distinguish one record from the other (at least Request ID). In order to delete Data from InfoCubes (selectively) use ABAP Report RSDRD_DELETE_FACTS (be carefull it does not request any confirmation as in RSA1 ...).
    About MM and SD Cubes see RSA1 -> Business Content -> InfoProvider by InfoAreas. See also for MetadataRepository about the same InfoProviders.
    About DataSources just execute TCode LBWE in you source sys: there you see all LO-Cockipt Extrators.
    Hope it helps (and if so remember reward points)
    GFV

  • How to delete duplicate records in all tables of the database

    I would like to be able to delete all duplicate records in all the tables of the database. Many of the tables have LONG columns.
    Thanks.

    Hello
    To delete duplicates from an individual table you can use a construct like:
    DELETE FROM
        table_a del_tab
    WHERE
        del_tab.ROWID <> (SELECT
                                MAX(dups_tab.ROWID)
                          FROM
                                table_a dups_tab
                          WHERE
                                dups_tab.col1 = del_tab.col1
                          AND
                                dups_tab.col2 = del_tab.col2
                          )You can then apply this to any table you want. The only differences will be the columns that you join on in the sub query. If you want to look for duplicated data in the long columns themselves, I'm pretty sure you're going to need to do some PL/SQL coding or maybe convert them to blobs or something.
    HTH
    David

  • How to delete Duplicate records from the informatica target using mapping?

    Hi, I have a scenario like below: In my mapping I have a source, which may containg unique records or duplicate records. Source and target are different tables. I have a target in my mapping which contains duplicate records. Using Mapping I have to delete the duplicate records in the target table. Target table does not contain any surrogate key. We can use target table as a look up table, but target table cannot be used as source in the mapping. We cannot use post SQL.

    Hi All, I have multiple flat files which i need to load in a single table.I did that using indirect option at session level.But need to dig out on how to populate substring of header in name column in target table. i have two columns Id and Name. in all input file I have only one column 'id' with header like H|ABCD|Date. I need to populate target like below example. File 1                                    File2     H|ABCD|Date.                      H|EFGH|Date.1                                            42                                            5  3                                            6 Target tale: Id    Name1     ABCD2     ABCD3     ABCD4     EFGH5     EFGH6     EFGH can anyone help on what should be the logic to get this data in a table in informatica.

  • Delete duplicate records issue

    Dear experts,
    i did one development 1 month back for send mail.
    In that i fetch email id of F_cord from one table(zcoordinator) based on some condition.now they want to changes in that object.
    now two new fields added in that table ven_cord and HOD, both have some mail id.
    As per their requirement , i need to fetch the ven_cord mail id and HOD mail id from that same table for priviously fetched F_cord.
    And I need to delete duplicate ven_cord from tha table.
    So for this should i need to create another structure or any ohther ways to solve the requirement.
    \Plase suggest ?
    Kin Regards,
    Ajit

    @sanjeev,
    I do't have create a separate structure for fetch these two fields ?
    As per you, I need to add these two new fields to that previous structure which I created for F_CORD, Wright ?
    And during fetch statement I need to add these two new fields. wright ?
    Then how to delete the duplicate ven_cord for the perticular F_CORD.
    Please suggst  ?
    I can't paste the code here ?
    Regards,
    Ajit

  • Delete duplicate record

    Hi All,
    I am using oracle 10g.
    I had 5 duplicate records in ore record, i have to delete 4 and keep 1.
    how to do?
    thanks

    These are the queries to get duplicate rows. put the unique keys in where clause which decide the duplications. With row id you can delete the one of row from duplicate rows.
    like delete from tab where rowid='sdfsdfsdfsd';
    SELECT
    Rowid,
    BOOK_UNIQUE_ID,
    PAGE_SEQ_NBR,
    IMAGE_KEY
    FROM
    page_image A
    WHERE
    rowid >
    (SELECT min(rowid) FROM page_image B
    WHERE
    B.key1 = A.key1
    and
    B.key2 = A.key2
    and
    B.key3 = A.key3
    select count(*),t.pir_number,t.internal_txn_nmbr,t.record_details
    from cms_funds_transfer t
    group by t.pir_number,t.internal_txn_nmbr,t.record_details
    having count (*) > 1;

  • How to Delete duplicate Records in Table

    CREATE GLOBAL TEMPORARY TABLE MyTable1 (
    Name1 varchar2(100)
    insert into MyTable1 values ('11');
    insert into MyTable1 values ('11');
    insert into MyTable1 values ('11');
    insert into MyTable1 values ('11');
    insert into MyTable1 values ('12');
    insert into MyTable1 values ('12');
    select * from MyTable1
    I want to delete duplicate names from MyTable1..And after delete I should have 11 and 22 only.

    I got the answer
    delete from MyTable1
    where rowid not in
    (select max(rowid)
    from MyTable1
    group by Name1
    having count(1) > 1
    )

Maybe you are looking for

  • B&W G3, no image on monitor

    I've looked around quite a bit, and I can't seem to find any other posts (here or on other sites) that deal with exactly this problem. I have a B&W G3 that's been upgraded quite a bit by the previous owner. It has a 500 mhz Sonnet G3 processor, 512 M

  • Time Machine problems behind network switch?

    Just installed a Netgear GS108T gigabit switch and placed my Mac Mini w/backup drives that was being used as a HTPC and Time Machine server behind it, along with the other computers. Neither my Macbook (wireless to router which is also plugged into s

  • Upgrading to Mavericks?

    Hi, last week an unexpected (and, for a second, suspicious) window appeared on my almost-5-year-old Macbook saying that I can upgrade to Mavericks for free. I googled it to find out more. Right now I have 10.6.8. Will my old Macbook manage the new OS

  • Release of APO Demand Planning to R/3 Demand Management

    Hi All, Is there a way to release the forecast in Demand Planning in APO to R/3 Demand Management without passing overwriting the historical buckets in R/3. I have created a special data view that does not contain any historical weeks. However, if we

  • ACE - Support for SSL Server Name Indication (SNI)

    Hi, I have the question if Cisco ACE currently or in the future supports SSL SNI (RFC 3546 or 4366). You run into that problem when moving SSL termination from a server that supports having multiple different certificates bound to the same IP and act