Alternative to find duplicate records

Hello

My requirement is to find records in doubles of the sub sample. But it takes more time to generate the output when you work for about 10 lakh of records.

Is there an alternative approach without the help of the JOIN. Thanks in advance

with aaa as

(select 101 as id, seq 1, "Asthma" as an event, 'medical' as an union journalist double

Select 101, 3, 'asthma', 'medi' Union double

Select 101, 2, 'lag', 'meddi' Union double

Select 102.2, "whooping cough", "LP" of double union

Select 102.1, "whooping cough", "LPS" double Union

102.4 select, "whooping cough", "LPWS' Union double

Select 102.3, 'ddd', 'dd' double Union

Select 103, 1, 'asthma', ' Union double

Select 103, 2, 'asta', have ' Union double

Select 104,2, "whooping cough", "xx" of the double

)

Select x.* from aaa x,

(SELECT id, event, count (*)

by aaa

Group by id, event

Having count (*) > 1

) b

where x.id = b.id

and x.event = b.event

something along the lines

with aaa as

(select 101 as id, 1 as seq, 'asthma' as event, 'medical' as reporter from dual union

select 101, 3, 'asthma', 'medi' from dual union

select 101, 2, 'lag', 'meddi' from dual union

select 102,2, 'whooping', 'LP' from dual union

select 102,1, 'whooping', 'LPS' from dual union

select 102,4, 'whooping', 'LPWS' from dual union

select 102,3, 'ddd', 'dd' from dual union

select 103, 1, 'asthma', 'm' from dual union

select 103, 2, 'asta', 'm' from dual union

select 104,2, 'whooping', 'xx' from dual

)
select * from (
select aaa.* , count(*) over (partition by id,event) rn from aaa
) where rn > 1;

Hope this helps

Alvinder

Tags: Database

Similar Questions

  • finding duplicate records in the DB table, or the data trasnpose

    Hello

    I have a question...

    Key | UID. Start Dt | End date. / / DESC


    --------------------------------------------------------------------------------
    1. 101 | March 12 09 | 30 May 09 | UID101

    2. 101 | January 1 09 | February 25 09 | UID101

    3. 102. 13 March 09 | 30 March 09 | UID102

    4. 103. 13 March 09 | 30 March 09 | UID103

    5. 103. 13 March 09 | April 1 09 | UID103

    6. 104. 13 March 09 | 30 May 09 | UID104

    7. 104. February 25 09 | 29 May 09 | UID104

    8. 105. 15 February 09 | March 1 09 | UID105

    9. 105. April 1 09 | 30 May 09 | UID105

    The query must know UID in duplicate according to the above data, which are stored in the same form in a table. The definition of the UID duplicate is

    (1) UID repeating themselves (records by 2) ex are 101,103,104 and 105.
    (2) each UID has two dates and date of end of beginning.
    (3) the UID for which dates are overlaping. For ex: touch #4, 103 UID whose start dates are March 13 09-30-Mar-09 and there also another record, with the # 5 UID 103 key dates are 13 Mar 09 to 1 April 09. Here, there is overlap or intersection in line #4 with key #5 key dates dates of rank. This UID is duplicated UID by def.

    What precedes that falls under def and selectable are 103 and 104 only 102 UID has only a single line, UID 105 dates are mutually exclusive or not that overlap and even for the UID.

    Is there a function available DB to make use of?


    Wanted not to delete records or duplicate records.

    There is a report to display these duplicate records.

    It would be good for me if I can get the data transposed for UID

    as

    Of

    4. 103. 13 March 09 | 30 March 09 | UID103

    5. 103. 13 March 09 | April 1 09 | UID103

    TO
    UID. Start the t1d. End t1d. Start the T2D. End T2D
    103: |13-Mar-09|30-Mar-091-Apr-09 13 March 09

    Any advice or ideas can be useful to gr8

    Thank you...

    It can also be done without Analytics:

    WITH test_data AS (
      SELECT  1 AS KEY, 101 AS UD, TO_DATE('03/12/2009','MM/DD/YYYY') AS START_DT, TO_DATE('05/30/2009','MM/DD/YYYY') AS END_DT, 'UD101' AS DSC FROM DUAL UNION ALL
      SELECT  2 AS KEY, 101 AS UD, TO_DATE('01/01/2009','MM/DD/YYYY') AS START_DT, TO_DATE('02/25/2009','MM/DD/YYYY') AS END_DT, 'UD101' AS DSC FROM DUAL UNION ALL
      SELECT  3 AS KEY, 102 AS UD, TO_DATE('03/13/2009','MM/DD/YYYY') AS START_DT, TO_DATE('03/30/2009','MM/DD/YYYY') AS END_DT, 'UD102' AS DSC FROM DUAL UNION ALL
      SELECT  4 AS KEY, 103 AS UD, TO_DATE('03/13/2009','MM/DD/YYYY') AS START_DT, TO_DATE('03/30/2009','MM/DD/YYYY') AS END_DT, 'UD103' AS DSC FROM DUAL UNION ALL
      SELECT  5 AS KEY, 103 AS UD, TO_DATE('03/13/2009','MM/DD/YYYY') AS START_DT, TO_DATE('04/01/2009','MM/DD/YYYY') AS END_DT, 'UD103' AS DSC FROM DUAL UNION ALL
      SELECT  6 AS KEY, 104 AS UD, TO_DATE('03/13/2009','MM/DD/YYYY') AS START_DT, TO_DATE('05/30/2009','MM/DD/YYYY') AS END_DT, 'UD104' AS DSC FROM DUAL UNION ALL
      SELECT  7 AS KEY, 104 AS UD, TO_DATE('02/25/2009','MM/DD/YYYY') AS START_DT, TO_DATE('05/29/2009','MM/DD/YYYY') AS END_DT, 'UD104' AS DSC FROM DUAL UNION ALL
      SELECT  8 AS KEY, 105 AS UD, TO_DATE('02/15/2009','MM/DD/YYYY') AS START_DT, TO_DATE('03/01/2009','MM/DD/YYYY') AS END_DT, 'UD105' AS DSC FROM DUAL UNION ALL
      SELECT  9 AS KEY, 105 AS UD, TO_DATE('04/01/2009','MM/DD/YYYY') AS START_DT, TO_DATE('05/30/2009','MM/DD/YYYY') AS END_DT, 'UD105' AS DSC FROM DUAL
    )
    select  t1.ud,
         t1.key, t1.start_dt, t1.end_dt,
         t2.key, t2.start_dt, t2.end_dt
    from     test_data t1
    ,     test_data t2
    where     t1.ud = t2.ud
      and     t1.key < t2.key
      and     ((t1.end_dt - t1.start_dt) + (t2.end_dt - t2.start_dt)) >
            (greatest(t1.end_dt, t2.end_dt) - least(t1.start_dt, t2.start_dt))
    /
    

    Result:

            UD        KEY START_DT   END_DT            KEY START_DT   END_DT
    ---------- ---------- ---------- ---------- ---------- ---------- ----------
           103          4 13-03-2009 30-03-2009          5 13-03-2009 01-04-2009
           104          6 13-03-2009 30-05-2009          7 25-02-2009 29-05-2009
    

    In addition, you will need to adjust the date a little comparison, depending on whether you set two periods where the first End_date is equal to the start_date in the second, because duplication or not.

    Published by: tijmen on December 21, 2009 06:17

  • How do to find duplicate records in a table, then delete them.

    Hi all

    I'm working on a database of GR 11, 2 under linux. Recently, we have created a unique index on two inplace of columns in a single-column index. When we try to create this index in pre-production and prod to get an error message saying that the "double values found. Now my team asked me to write a pl/sql package or procedure to find these duplicate values and remove it or any other way to do it for them as well. But I'm not familiar with stuff of PL/SQL or data level how to perform this task.
    Please help me on this issue, how can I proceed.
    Thanks in advance for your help.

    Try this:

    
    CREATE TABLE z_test2
    AS
       SELECT 1 a, 'aaa' b FROM DUAL
       UNION ALL
       SELECT 1 a, 'aaa' b FROM DUAL
       UNION ALL
       SELECT 1 a, 'bbbb' b FROM DUAL
       UNION ALL
       SELECT 12 a, 'aaa' b FROM DUAL
       UNION ALL
       SELECT 12 a, 'aaa' b FROM DUAL
       UNION ALL
       SELECT 12 a, 'aaa' b FROM DUAL
       UNION ALL
       SELECT 13 a, 'aaa' b FROM DUAL;
    
    DELETE FROM z_test2 x
          WHERE EXISTS
                   (SELECT '*'
                      FROM (SELECT a,
                                   b,
                                   ROW_NUMBER ()
                                      OVER (PARTITION BY a, b ORDER BY a)
                                      rn
                              FROM z_test2) y
                     WHERE x.a = y.a AND x.b = y.b AND rn > 1);
    
                     
    
  • Find duplicate records in the fields.

    Hi all

    There are 5 A B C D E of type Varchar fields in my table x. 4 A B C D fields are key fields.

    I would like to ask two copies of the fields in the fields A B C D.

    Please suggest me.

    Thank you
    KSG

    Hello
    Simply:

    SELECT A, B, C, D, Count(*)
      FROM your_table
     GROUP BY A, B, C, D HAVING Count(*) > 1;
    
  • Marking duplicate records

    Hi gurus of the Oracle,.

    Good morning/afternoon/evening!

    There are several methods to effectively identify duplicate records. e.g. row_number() and group by, but all of these methods to highlight the duplicate record only. Which means that if your table has data such as

    IDNameRoomDate
    1ABC20320/07/2015
    2FGH10920/09/2015
    3HSF20220/08/2015
    4REF20120/08/2015
    5FGH10920/09/2015
    6HSF29124/08/2015

    And I want to find duplicates based on name/room/day

    Most of the queries will give me

    Or the other

    IDNameRoomDate
    5FGH10920/09/2015

    or

    IDNameRoomDate
    2FGH109

    20/09/2015

    They don't give me two files unless I first do a group by (or Row_Number) in an internal query and then try to get the two lines in the outer query. In my view, should not be the way.

    I need a report which highlights the two records only

    IDNameRoomDate
    2FGH10920/09/2015
    5FGH10920/09/2015

    Hope that is clear.

    Thanks in advance!

    Hello

    34MCA2K2 wrote:

    Hi gurus of the Oracle,.

    Good morning/afternoon/evening!

    There are several methods to effectively identify duplicate records. e.g. row_number() and however all these methods to highlight only the duplicate of group by. Which means that if your table has data such as

    ID Name Room Date
    1 ABC 203 20/07/2015
    2 FGH 109 20/09/2015
    3 HSF 202 20/08/2015
    4 REF 201 20/08/2015
    5 FGH 109 20/09/2015
    6 HSF 291 24/08/2015

    And I want to find duplicates based on name/room/day

    Most of the queries will give me

    Or the other

    ID Name Room Date
    5 FGH 109 20/09/2015

    or

    ID Name Room Date
    2 FGH 109

    20/09/2015

    They don't give me two files unless I first do a group by (or Row_Number) in an internal query and then try to get the two lines in the outer query. In my view, that shouldn't be the way...

    Help the ROW_NUMBER analytic function, that you described is probably the easiest and most effective way to get the desired results.

    You can do it without using any kind of subquery (for example, with a self-join or CONNECT BY), but which requires SELECT DISTINCT, which is inefficient.

  • ROW_NUMBER and duplicate records

    Hello

    Tried to delete duplicate records. The code below works, but would remove all, rather than simply the > #1 records:

    (SELECT academic_period, load_week, sub_academic_period, person_uid, course_number,
    course_reference_number, rowid that RID, row_number() over (partition of)
    academic_period, load_week, sub_academic_period, person_uid, course_number,
    order of course_reference_number of academic_period, load_week, sub_academic_period,
    person_uid, course_number, course_reference_number)
    Of THE cea
    WHERE (academic_period, load_week, sub_academic_period, person_uid, course_number,)
    IN course_reference_number)
    (SELECT academic_period, load_week, sub_academic_period, person_uid, course_number,
    course_reference_number
    Of THE cea
    GROUP of academic_period, load_week, sub_academic_period, person_uid, course_number,
    course_reference_number
    HAVING COUNT (*) > 1))


    If I try to put 'rn' and rn > 1, I get ora-00933: Sql not correctly completed command

    SELECT academic_period, load_week, sub_academic_period, person_uid, course_number,
    course_reference_number, rowid that RID, row_number() over (partition of)
    academic_period, load_week, sub_academic_period, person_uid, course_number,
    order of course_reference_number of academic_period, load_week, sub_academic_period,
    person_uid, course_number, course_reference_number): the nurse
    Of THE cea
    WHERE (academic_period, load_week, sub_academic_period, person_uid, course_number,)
    IN course_reference_number)
    (SELECT academic_period, load_week, sub_academic_period, person_uid, course_number,
    course_reference_number
    Of THE cea
    GROUP of academic_period, load_week, sub_academic_period, person_uid, course_number,
    course_reference_number
    After HAVING COUNT (*) > 1)
    and rn > 1

    I tried to remove as"rn" and make "rn" and "rn", which gave me an error of syntax also. The '' rn > 1 and '' clause gets an error of syntax also. I gone through a bunch of different Web sites. All of this indicates the syntax I am using will work. However, any query I run into a TOAD, always error when I include the 'rn > 1.

    Any ideas? Thank you!

    Victoria

    You mix two ways to identify duplicates.

    One way is HAVING:

    SELECT academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number
    FROM cea
    GROUP BY academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number
    HAVING COUNT(*) > 1)
    

    That tells you just what combinations of your group are more than once.

    Another way is to analytical functions:

    select *
    from (
      SELECT academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number
             count(*) over (partition by academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number) cnt
      FROM cea
    )
    where cnt > 1
    

    This will all return duplicate records - if some combinations has three duplicates, then this will return all three lines.

    If you use the ROW_NUMBER() place COUNT() analytical analytical function, you get this:

    select *
    from (
      SELECT academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number
             row_number() over (partition by academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number) rn
      FROM cea
    )
    where rn > 1
    

    All of these files without duplicates will get rn = 1. Those with duplicates gets rn = 1, rn = 2... If rn > 1 Gets all "unnecessary" records - the ones you want to remove.

    If a deletion might look like:

    delete cea
    where rowid in (
      select rid
      from (
        SELECT ROWID as rid,
               row_number() over (partition by academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number) rn
        FROM cea
      )
      where rn > 1
    )
    

    Or if you want to manually inspect before you delete ;-):

    select *
    from cea
    where rowid in (
      select rid
      from (
        SELECT ROWID as rid,
               row_number() over (partition by academic_period, load_week, sub_academic_period, person_uid, course_number, course_reference_number) rn
        FROM cea
      )
      where rn > 1
    )
    

    In another answer, you can find a way to remove duplicates with HAVING.
    The point is that do you it either with or with ROW_NUMBER() - not both HAVING ;-)

  • How to remove duplicate records...

    Hello

    I have a strange scenario below is the structure of the table

    of km
    Bangalore, Mumbai 100
    Mumbai, Bangalore 100
    Bangalore, Chennai 50

    I want the output as given that the distance is even bangalore to Bombay and mumbai to bangalore I want only one instance...

    of km
    Bangalore, Mumbai 100
    Bangalore, Chennai 50

    I was able to find duplicate using following query records but put not able to come to the final...

    Select a.frm, b.frm, a.km
    distance a distance b
    where a.frm = b.too
    and b.frm = a.too

    Thanks in advance...


    Sree
    WITH t AS (
                SELECT 'Bangalore' col1, 'Mumbai' col2, 100 col3 FROM DUAL
               UNION ALL
                SELECT 'Mumbai', 'Bangalore', 100 FROM DUAL
               UNION ALL
                SELECT 'Bangalore', 'Chennai', 50 FROM DUAL
              )
    SELECT  DISTINCT LEAST(col1,col2) col1,
                     GREATEST(col1,col2) col1,
                     col3
      FROM  t
    /
    
    COL1      COL1            COL3
    --------- --------- ----------
    Bangalore Mumbai           100
    Bangalore Chennai           50
    
    SQL> 
    

    SY.

  • I can't find the recorded files recently in my document folder

    I can't find the recorded files recently in my document folder

    Maybe not save them there.

    Assuming that you have saved the today, go to the Finder, type 'Today' in the oval at top right.

  • How can I find duplicate photos?

    How can I find duplicate photos?

    On Photos for Mac?

    Photos will find them for you, when you migrate iPhoto library to Photos, or when you import pictures, or transfer the pictures to iCloud photo library. on these occasions photos is searching for duplicate photos and store the originals in doubles only once. It is so unlikely, that you have an exact replica of the original images in your photo library, you can have versions however duplicate of the same photo, if you he duplicated before edit. Duplicate versions don't require storage space.

    If you have duplicate pictures Photos could not recognize them as duplicates, because the original files are different in some way, Photos can not detect them.  In this case, you need a tool to search for them. Photo Sweeper can compare images based on histograms or bitmaps and detect duplicate versions, which have been scaled down in resolution or edited.

  • I find these records long name with 20 or more charactors and inside them is nothing else than "mrt.exe" file. I find them in random places.

    Original title: MRT. EXE files are all over my computer.

    I find these records long name with 20 or more charactors and inside them is nothing else than "mrt.exe" file. I find them in random places on my drive c: and many of them on my external G drive in the root. A new appears approximately every three months.

    I know the mrt.exe is supposed to have something to do with the malicious software removal tool, so I don't want to just delete them and have a problem.

    Allen

    Hello

    Are you prevents the tool from running?

    See Q21 at the end of this article

    The Microsoft Windows malicious software removal tool helps remove specific and prevalent malicious
    software for computers running Windows 7, Windows Vista, Windows Server 2003, Windows
    Server 2008, or Windows XP
    http://support.Microsoft.com/kb/890830

    What you do not know the Windows Malicious Software Removal Tool
    http://blogs.Computerworld.com/what_you_dont_know_about_the_windows_malicious_software_removal_tool

    What is Windows Malicious Software Removal Tool (mrt.exe) and how to use it
    http://www.vista4beginners.com/Windows-malicious-software-removal-tool?page=1

    I hope this helps.

    Rob Brown - MS MVP - Windows Desktop Experience: Bike - Mark Twain said it right.

  • Error on push notifications "cannot find any record of application settings.

    Hi im getting the error "Unable to find any record of application settings", with status 0 code. I hope someone can help me.

    private function addNotificationToHub():void
    {
    NotificationManager.notificationManager.addEventListener(ErrorEvent.ERROR, onNotificationError);
    NotificationManager.notificationManager.notifyNotification(notification);
    }
    
    private function onNotificationError(event:ErrorEvent):void
    {
    trace(event.errorID);
    }
    

    Thank you

    Javier

    I got it to notify the notification with the NotificationManager.notificationManager.notifyNotification () method, we need to display notification post_notification permission on bar - descriptor.xml authorisation to work.

    I found this error in google or here perhaps because almost everyone followed the tutorial on message notification.

    He also worked for me before, but the descriptorfile has been changed for some reason any and I do not notice it.

  • find duplicate files

    is there a process to find and remove duplicate system files

    There is no process within Windows that detects duplicate files.

    There are third-party programs that can find duplicate files.

    I would be very careful about deleting what appear to be duplicates, including system files. They can actually not be any duplicates.

    What you're trying to achieve?

  • Find no records in an Excel sheet

    Hi all

    I am importing data from an excel file into oracle database. I wanted to know the number of records in an excel file and no columns using oracle webutil (Client_ole2). I received a web code that works very well, adding a NEM statement at the end of the file each time. Maybe it's not practical always, cannot ask user each time to add a statement of NEM, which in turn result in program to run infinitely.

    This is the code that is running

    DECLARE

    application Client_OLE2. Obj_Type;

    Client_OLE2 workbooks. Obj_Type;

    workbook Client_OLE2. Obj_Type;

    Client_OLE2 spreadsheets. Obj_Type;

    worksheet Client_OLE2. Obj_Type;

    worksheet2 Client_OLE2. Obj_Type;

    cell Client_OLE2. OBJ_TYPE;

    Client_OLE2 args. OBJ_TYPE;

    cell_value varchar2 (100);

    num_wrkshts NUMBER;

    wksht_name VARCHAR2 (250);

    EOD Boolean: = false;

    j integer: = 3;

    v_fName VARCHAR2 (250);

    worksheet_count number: = 0;

    BEGIN

    -Get the name of the file to open

    -v_fName: = "D:\MyDevelopment\Forms\Samples\WebUtil\Read_Excel\planets3.xls";

    v_fName: = WebUtil_File.File_Open_Dialog)

    directory_name = > "C:\". »

    -, file_name = > Get_Form_Property (:System.Current_form, Form_Name) |'. XLS

    , File_Filter = > null

    , Title = > 'Select customer filename to open.'

    );

    IF (v_fName IS NOT NULL) THEN

    -The following sets a communication with the excel worksheet

    -- --------------------------------------------------------------

    -Open the OLE application

    application: = Client_OLE2.create_obj ('Excel.Application');

    -Keep the hidden application

    Client_OLE2.set_property (application, 'Visible ','false ');

    workbooks: = Client_OLE2. Get_Obj_Property (application "Filing cabinets");

    args: = Client_OLE2. CREATE_ARGLIST;

    -Open the selected file

    -- ----------------------

    Client_OLE2.add_arg (args, v_fName);

    workbook: = Client_OLE2. GET_OBJ_PROPERTY (Workbooks, 'Open', args);

    Client_OLE2.destroy_arglist (args);

    worksheets: = Client_OLE2. GET_OBJ_PROPERTY (workbook, 'Worksheets');

    -Get the number of spreadsheets

    -- ------------------------

    num_wrkshts: = Client_OLE2. GET_NUM_PROPERTY (worksheets, 'Count');

    worksheet: = Client_OLE2. GET_OBJ_PROPERTY (application, 'activesheet');

    -Go to the first record

    go_block ('EXCEL_EXPORT_TABLE');

    premier_enregistrement;

    loop

    If: system.record_status <>'NEW' then

    create_record;

    end if;

    When the exit NEM;

    for 1.15 k loop - 15 frames / record - hard-code the length of the column

    args: = Client_OLE2.create_arglist;

    Client_OLE2.add_arg (args, j);

    Client_OLE2.add_arg (args, k);

    cell: = Client_OLE2.get_obj_property (spreadsheet calculation, 'Cells', args);

    Client_OLE2.destroy_arglist (args);

    If Client_OLE2.get_char_property (cell, 'Value') = 'null' then

    cell_value: = ";

    on the other

    cell_value: = nvl (Client_OLE2.get_char_property (cell, 'Value'), 0);

    end if;

    If upper (cell_value) = 'NEM' then - the loop runs until "NEM" are judged.

    Nem: = true;

    Message ('end of data');

    "exit";

    end if;

    Copy (cell_value, name_in ('system.cursor_item'));

    next_item;


    end loop; -for

    j: = j + 1;

    end loop;-main loop

    premier_enregistrement;

    -Release the handles object Client_OLE2

    IF (cell IS NOT NULL) THEN

    Client_OLE2.release_obj (cell);

    END IF;

    IF (spreadsheet IS NOT NULL) THEN

    Client_OLE2.release_obj (Worksheet);

    END IF;

    IF (spreadsheets IS NOT NULL) THEN

    Client_OLE2.release_obj (Worksheets);

    END IF;

    IF (worksheet2 IS NOT NULL) THEN

    Client_OLE2.release_obj (worksheet2);

    END IF;

    IF (workbook IS NOT NULL) THEN

    Client_OLE2.release_obj (Workbook);

    END IF;

    IF (workbooks IS NOT NULL) THEN

    Client_OLE2.release_obj (Workbooks);

    END IF;

    Client_OLE2. Invoke (application, 'Quit');

    Client_OLE2.release_obj (application);

    ON THE OTHER

    Message ("no file selected.'");

    message(' ');

    RAISE Form_Trigger_Failure;

    END IF;

    END;

    Please think it has no integrated to find no records and columns in excel file using oracle forms.

    Thank you and best regards,

    JaKes

    This change according to excel data file.

    for example, we also use this logic. because the first column in excel file still does not empty. It should be full.

    If any column of a raw material can be empty, one with just my solution can be

    v_all_column_str: = col_A_Value | col_B_Value | col_C_Value | col_D_Value |... col_n_value;

    if v_all_column_str is null, then--> you can tell, all of the columns of this vintage in excellent file is empty

  • Matching records between 2 tables with duplicate records

    Hi all

    I need help in what follows.

    I have 2 tables Received_bills and Send_bills.

    -------------------------------------------------------

    -The DOF for Table SEND_BILLS

    --------------------------------------------------------

    CREATE TABLE SEND_BILLS

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

    --------------------------------------------------------

    -The DOF for Table RECEIVED_BILLS

    --------------------------------------------------------

    CREATE TABLE 'RECEIVED_BILLS '.

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE),

    VARCHAR2 (5 BYTE) 'STATUS' )  ;

    INSERTION of REM in RECEIVED_BILLS

    TOGETHER TO DEFINE

    Insert. RECEIVED_BILLS (DATUM, PAYMENT, CODE, STATE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 'A5', 'SUCCESS', 25);

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    INSERTION of REM in SEND_BILLS

    TOGETHER TO DEFINE

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    I match all records of send_bills and received_bills with a status of 'SUCCESS' There is no single column in the table.

    Correspondence held payment of columns, the code and the scratch cards, but it may also duplicate records. But even if there are duplicates, I also need those records in the query results

    the query I wrote is this:

    SELECT SEND.*

    REC received_bills, send_bills send

    WHERE send.datum = rec.datum

    AND send.payment = rec.payment

    AND send.code = rec.code

    AND 'rec.status =' SUCCESS

    ;

    The query results give me this

    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5

    The result of the correct application would be

    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5
    OCTOBER 10, 1519A1

    The select statement that I need I want to use a loop to insert records in another table.

    Can someone help me please?

    Thanks in advance.

    Best regards

    Caroline

    Hi, Caroline.

    Caroline wrote:

    Hi all

    I need help in what follows.

    I have 2 tables Received_bills and Send_bills.

    -------------------------------------------------------

    -The DOF for Table SEND_BILLS

    --------------------------------------------------------

    CREATE TABLE SEND_BILLS

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

    --------------------------------------------------------

    -The DOF for Table RECEIVED_BILLS

    --------------------------------------------------------

    CREATE TABLE 'RECEIVED_BILLS '.

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE),

    VARCHAR2 (5 BYTE) 'STATUS');

    INSERTION of REM in RECEIVED_BILLS

    TOGETHER TO DEFINE

    Insert. RECEIVED_BILLS (DATUM, PAYMENT, CODE, STATE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 'A5', 'SUCCESS', 25);

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'FAILED');

    Insert into RECEIVED_BILLS (PAYMENT, CODE, DATE, STATUS) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1', 'SUCCESS');

    INSERTION of REM in SEND_BILLS

    TOGETHER TO DEFINE

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5');

    I match all records of send_bills and received_bills with a status of 'SUCCESS' There is no single column in the table.

    Correspondence held payment of columns, the code and the scratch cards, but it may also duplicate records. But even if there are duplicates, I also need those records in the query results

    the query I wrote is this:

    SELECT SEND.*

    REC received_bills, send_bills send

    WHERE send.datum = rec.datum

    AND send.payment = rec.payment

    AND send.code = rec.code

    AND 'rec.status =' SUCCESS

    ;

    The query results give me this

    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 25 A5
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 25 A5

    The result of the correct application would be

    OCTOBER 10, 15 19 A1
    OCTOBER 10, 15 25 A5
    OCTOBER 10, 15 19 A1

    The select statement that I need I want to use a loop to insert records in another table.

    Can someone help me please?

    Thanks in advance.

    Best regards

    Caroline

    Want to get answers that work?  Then make sure that the CREATE TABLE and INSERT statements you post too much work.  Test (and, if necessary, correct) your statements before committing.  You have a stray "." in the first INSERT statement for received_bills and receikved_bills.status is defined as VARCHAR2 (5), but all values are 6 characters long.

    There are 5 lines in send_bills that are similar to the

    10 OCTOBER 2015 19 A1

    Why do you want that 2 rows like this in the output, not 1 or 3, or 4 or 5?  Is it because there are 2 matching rows in received_bills?  If so, you can do something like this:

    WITH rec AS

    (

    SELECT the reference, payment, code

    , ROW_NUMBER () OVER (PARTITION BY datum, payment, code)

    ORDER BY NULL

    ) AS r_num

    OF received_bills

    Situation WHERE = 'SUCCESS'

    )

    send AS

    (

    SELECT the reference, payment, code

    , ROW_NUMBER () OVER (PARTITION BY datum, payment, code)

    ORDER BY NULL

    ) AS r_num

    OF send_bills

    )

    SELECT send.datum, send.payment, send.code

    REC, send

    WHERE send.datum = rec.datum

    AND send.payment = rec.payment

    AND send.code = rec.code

    AND send.r_num = rec.r_num

    ;

    Note that the main request is very similar to the query you posted, but the last condition has changed.

    If you need to insert these lines in another table, you can use this query in an INSERT statement. There is no need of a loop, or for any PL/SQL.

  • Find duplicates of some merged ID

    Extend the discussion I had recently by https://community.oracle.com/thread/3774735?sr=inbox , now I need to find duplicates in a table on which some data had been already merged.

    Here ar a few test cases:

    create table test_tbl
    ( 
      IDM NUMBER(9) NOT NULL
    
    
    
    ,  ID_MERGE
    NUMBER(9)
    
    
    ,  CURRENT_ID
    NUMBER(9)
    
    
    
    , SNAME VARCHAR2(20) 
    , FNAME VARCHAR2(20) 
    , DBIRTH VARCHAR2(15)  
    ); 
    
    
    

    And the data are:

    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (125,NULL,125,'BOLOREY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (129,1000,1000,'BOLOREY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (127,1000,1000,'BOLOREY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (128,NULL,128,'BOLOREY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (126,1003,1003,'BOLLOREY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (123,1003,1003,'BOLLOREY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (131,1003,1003,'BOLLOREY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (150,NULL,150,'BOLLOREY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (133,NULL,133,'BOLLOREY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (153,NULL,153,'BALORE','GIANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (223,NULL,223,'ABOLLOREYY','JEANNE','11/05/1955');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (225,NULL,225,'FIABLE','MARINE','25/04/1963');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (226,1001,1001,'FIABLE','MARINE','25/04/1963');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (227,1001,1001,'FIABLE','MARINE','25/04/1963');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (228,1005,1005,'RINTET','MALIKA','07/08/1954');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (229,1005,1005,'RINTET','MALIKA','07/08/1954');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (240,NULL,240,'RINTET','MALIKA','07/08/1954');
    Insert into members_tbl (IDM, ID_MERGE, CURRENT_ID, SNAME, FNAME, DBIRTH) values (241,NULL,241,'RINTET','MALIKA','07/08/1954');
    



    My goals are the same: use a temporary table to count in a second time duplicates; so, if I used the merged column:

    CREATE TABLE test_dbl as
    SELECT    m1.idm
    ,         m2.idm                                    AS dup_key
    ,         COUNT (*) OVER (PARTITION BY m1.idm)   AS dup_num
    FROM      MEMBERS_TBL  m1
    JOIN      MEMBERS_TBL  m2 ON  
                               
                                  m1.idm      !=    m2.idm
                           AND    m1.id_merge =  m2.id_merge  -- m1.idmerge = null  or m2.idmerge = null 
                           AND    m1.dbirth  =   m2.dbirth
                           AND  m1.fname  = m2.fname 
                           AND  m1.sname  = m2.sname 
    ORDER BY  idm
    ,         dup_key
    ;
    
    

    and when you count all the duplicates it gives me 9; But if If I insert m1.idmerge = null or m2.idmerge = null, I have no results

    SELECT SUM(TOTAL_TYP_DBL) AS NBRE_DBL_STR_AV_NSS
    FROM (
    SELECT TYPE_DOUBLONS, COUNT(TYPE_DOUBLONS) AS TOTAL_TYP_DBL
    FROM (
    SELECT IDM,
    case count(*)
            when 1 then 'Doublons'  -- IDM + 1 duplicate = 2
            when 2 then 'Triplons'  -- IDM + 2 duplicates = 3
            when 3 then 'Quadruplons'
            when 4 then 'Quintuplons'
            when 5 then 'Sextuplons'
            when 6 then 'Septuplons'
            when 7 then 'Octuplons'
            when 8 then 'Nonuplons'
            when 9 then 'Décuplons'
            when 10 then 'Undécuplons'
            else 'Dodécuplons et plus'
            end as TYPE_DOUBLONS
            --count(*)+1 as dbl_cmp
    FROM TEST_DBL
    GROUP BY idm
    --where TYPE_DOUBLONS ='Dodécuplons et plus'
    )
    GROUP BY TYPE_DOUBLONS
    )
    ;
    
    

    And it's not just because I have to take into account the new merged id (NULL or NOT)

    Can someone please get a sense of how to write it in pl/sql please?

    Thanks in advance

    This message was edited by: 2986888 there are a few errors on the sample data.

    Hello

    2986888 wrote:

    I tried to adapt your suggestion again and now I have this query that seems to work:

    1. CREATE TABLE test_dbl as
    2. SELECT m1.idm
    3. m2.idm AS dup_key
    4. COUNT AS dup_num (*) OVER (PARTITION BY m1.idm)
    5. MEMBERS_TBL M1
    6. JOIN MEMBERS_TBL m2 WE
    7. M1. IDM! = m2.idm
    8. AND ((DECODE (m1.id_merge, m2.id_merge, 0, 1) = 0) OR (DECODE (m1.id_merge, NULL, 0, 1) = 1) OR (DECODE (NULL, m2.id_merge, 0, 1) = 1))
    9. AND m1.dbirth = m2.dbirth
    10. AND m1.fname = m2.fname
    11. AND m1.sname = m2.sname
    12. ORDER BY idm
    13. dup_key
    14. ;

    Wat is your point of view?

    During the id_merge comparison, it looks like you want 2 rows to match when the id_merge, m1 = m2, id) merge OR when one is NULL, regardless of whether the other is NULL or neither.  Is that what you want?  (I don't see anything above about in this thread.)

    If so, what you posted should work, but there are easier ways to do what you do online 09 above.  For example:

    SELECT m1.idm

    m2.idm AS dup_key

    COUNT AS dup_num (*) OVER (PARTITION BY m1.idm)

    MEMBERS_TBL M1

    JOIN MEMBERS_TBL m2 WE m1.idm! = m2.idm

    AND LNNVL (m1.id_merge! = m2.id_merge)

    AND m1.dbirth = m2.dbirth

    AND m1.fname = m2.fname

    AND m1.sname = m2.sname

    ORDER BY idm

    dup_key

    ;

    If you don't want not calibrated LNNVL that it is difficult to understand, then you should lose DECODE for the same reason and make the comparison id_merge like this:

    AND (m1.id_merge = m2.id_merge - not! = I posted)

    OR m1.id_merge IS NULL

    OR m2.id_merge IS NULL

    )

    [EDIT: I see now that the stew already suggested this in response #8, above.]

Maybe you are looking for