Need to remove duplicate rows from a table

Hi Gurus ,
I am using oracle 11.2.0.3 .
SQL> desc osstage.S_EVT_ACT_X;
Name                                      Null?    Type
ROW_ID                                    NOT NULL VARCHAR2(15 CHAR)
LAST_UPD                                  NOT NULL DATE
PAR_ROW_ID                                NOT NULL VARCHAR2(15 CHAR)
ATTRIB_17                                          NUMBER(22,7)
ATTRIB_26                                          DATE
ATTRIB_02                                          VARCHAR2(100 CHAR)
PROCESS_TIMESTAMP                                  TIMESTAMP(6);
now when i give the below command it gives the error as someone has disabled the constraint accidently .
alter table s_evt_act_x enable constraint S_EVT_ACT_X_P1;
Error starting at line 3 in command:
alter table s_evt_act_x enable constraint S_EVT_ACT_X_P1
Error report:
SQL Error: ORA-02437: cannot validate (OSSTAGE.S_EVT_ACT_X_P1) - primary key violated
02437. 00000 -  "cannot validate (%s.%s) - primary key violated"
*Cause:    attempted to validate a primary key with duplicate values or null
           values.
*Action:   remove the duplicates and null values before enabling a primary
           key.
Can you please guide me with this issue .

Please refer
Script: Deleting Duplicate Rows from a Table (Doc ID 31413.1)
How to Find or Delete Duplicate Rows in a Table (Doc ID 1004425.6)

Similar Messages

  • First attempt to remove duplicate rows from a table...

    I have seen many people asking for a way to remove duplicate rows from data. I made up a fairly simple script. It adds a column to the table with the cell selected in it, and adds the concatenation of the data to the left into that new column. then it reads that into a list, and walks through that list to find any that are listed twice. Any that are it marks for DELETE.
    It then walks through to find each one marked for delete and removes them (you must go from bottom to top to do this, otherwise your row markings for delete don't match up to the original rows anymore). Last is to delete the column we added.
    tell application "Numbers"
    activate
    tell document 1
    -- DETERMINE THE CURRENT SHEET
    set currentsheetindex to 0
    repeat with i from 1 to the count of sheets
    tell sheet i
    set x to the count of (tables whose selection range is not missing value)
    end tell
    if x is not 0 then
    set the currentsheetindex to i
    exit repeat
    end if
    end repeat
    if the currentsheetindex is 0 then error "No sheet has a selected table."
    -- GET THE TABLE WITH CELLS
    tell sheet currentsheetindex
    set the current_table to the first table whose selection range is not missing value
    end tell
    end tell
    log current_table
    tell current_table
    set list1 to {}
    add column after column (count of columns)
    set z to (count of columns)
    repeat with j from 1 to (count of rows)
    set m to ""
    repeat with i from 1 to (z - 1)
    set m to m & value of (cell i of row j)
    end repeat
    set value of cell z of row j to m
    end repeat
    set MyRange to value of every cell of column z
    repeat with i from 1 to (count of items of MyRange)
    set n to item i of MyRange
    if n is in list1 then
    set end of list1 to "Delete"
    else
    set end of list1 to n
    end if
    end repeat
    repeat with i from (count of items of list1) to 1 by -1
    set n to item i of list1
    if n = "Delete" then remove row i
    end repeat
    remove column z
    end tell
    end tell
    Let me know how it works for y'all, it worked good on my machine, but I know localization is causing errors sometimes when I post things.
    Thanks,
    Jason
    Message was edited by: jaxjason

    Hi jason
    I hope that with the added comments it will be clear.
    Ask if something is always opaque.
    set {current_Range, current_table, current_Sheet, current_Doc} to my getSelection()
    tell application "Numbers09"
    tell document current_Doc to tell sheet current_Sheet to tell table current_table
    set list1 to {}
    add column after column (count of columns)
    set z to (count of columns)
    repeat with j from 1 to (count of rows)
    set m to ""
    tell row j
    repeat with i from 1 to (z - 1)
    set m to m & value of cell i
    end repeat
    set value of cell z to m
    end tell
    end repeat
    set theRange to value of every cell of column z
    repeat with i from (count of items of theRange) to 1 by -1
    (* As I scan the table backwards (starting from the bottom row),
    I may remove a row immediately when I discover that it is a duplicate *)
    set n to item i of theRange
    if n is in list1 then
    remove row i
    else
    set end of list1 to n
    end if
    end repeat
    remove column z
    end tell
    end tell
    --=====
    on getSelection()
    local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
    tell application "Numbers09" to tell document 1
    set theSheet to ""
    repeat with i from 1 to the count of sheets
    tell sheet i
    set x to the count of tables
    if x > 0 then
    repeat with y from 1 to x
    (* Open a trap to catch the selection range.
    The structure of this item
    «class
    can't be coerced as text.
    So, when the instruction (selection range of table y) as text
    receive 'missing value' it behaves correctly and the lup continue.
    But, when it receive THE true selection range, it generates an error
    whose message is errMsg and number is errNum.
    We grab them just after the on error instruction *)
    try
    (selection range of table y) as text
    on error errMsg number errNum (*
    As we reached THE selection range, we are here.
    We grab the errMsg here. In French it looks like:
    "Impossible de transformer «class
    The handler cuts it in pieces using quots as delimiters.
    item 1 (_) "Impossible de transformer «class » "
    item 2 (theRange) "A2:M25"
    item 3 (_) " of «class NmTb» "
    item 4 (theTable) "Tableau 1"
    item 5 (_) " of «class NmSh» "
    item 6 (theSheet) "Feuille 1"
    item 7 (_) " of document "
    item 8 (theDoc) "Sans titre"
    item 9 ( I drop it ) " of application "
    item 10 ( I drop it ) "Numbers"
    item 11 (I drop it ) " en type string."
    I grab these items in the list
    {_, theRange, _, theTable, _, theSheet, _, theDoc}
    Yes, underscore is a valid name of variable.
    I often uses it when I want to drop something.
    An alternate way would be to code:
    set ll to my decoupe(errMsg, quote)
    set theRange to item 2 of ll
    set theTable to item 4 of ll
    set theSheet to item 8 of ll
    set theDoc to item 10 of ll
    it works exactly the same but it's not so elegant.
    set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
    exit repeat (*
    as we grabbed the interesting datas, we exit the lup indexed by y.*)
    end try
    end repeat -- y
    if theSheet > "" then exit repeat (*
    If we are here after grabbing the datas, theSheet is not "" so we exit the lup indexed by i *)
    end if
    end tell -- sheet
    end repeat -- i
    (* We may arrive here with two kinds of results.
    if we grabbed a selection, theSheet is something like "Feuille 1"
    if we didn't grabbed a selection, theSheet is the "" defined on entry
    and we generate an error which is not trapped so it stops the program *)
    if theSheet = "" then error "No sheet has a selected table."
    end tell -- document
    (* Now, we send to the caller the interesting datas :
    theRange "A2:M25"
    theTable "Tableau 1"
    theSheet "Feuille 1"
    theDoc "Sans titre" *)
    return {theRange, theTable, theSheet, theDoc}
    end getSelection
    --=====
    on decoupe(t, d)
    local l
    set AppleScript's text item delimiters to d (*
    Cut the text t in pieces using d as delimiter *)
    set l to text items of t
    set AppleScript's text item delimiters to "" (*
    Resets the delimiters to the standard value. *)
    (* Send the list to the caller *)
    return l
    end decoupe
    --=====
    Have fun
    And if it's not clear enough, you may ask for more explanations.
    Yvan KOENIG (from FRANCE mardi 27 janvier 2009 21:49:19)

  • Need to remove duplicate rows from distinct query

    Hello,
    I have the following query:
    SELECT tiab.abnr abnr, tiab.namn namn, (CAST(tiab.GATUNR||' '||tiab.gata AS VARCHAR2(254))) ADR, tiab.boxpnr boxpnr, tiab.boxort boxort,
              (CAST(tiab.RIKTNRDISPLAY AS VARCHAR2(254))) RIKTNR, (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) TELNR,
    DECODE((select count(tior.tigilopnr) from tis.tior where abnr = tiab.abnr and inplnr IN (3797886)),0 ,NULL , 1, tior.tigilopnr, 'N/A') tigilopnr
              FROM tis.tiab
    JOIN tis.tior on tiab.abnr = tior.abnr
              WHERE tior.inplnr IN (3797886)
              ORDER BY tiab.ABNR )
    ORDER BY abnr;
    It returns the following:
         14684940     Pizza Station Inc The     Lafayette     26170      St Marys     304     684-2411     
         15123161     Chris Test     554 Easy St n 43333      Columbus     614     555-5555     
         15123162     Chris Test2     5556 Easy St     43333     Columbus     614     555-5151     2553304 --> keep this one
         15123162     Chris Test2     5556 Easy St     43333     Columbus     614     555-5151     -- not show this
    I have tried several different things as well as looking through the forums but have not found anything that will only give me unique records based only on the first column. This query works fine as long as there
    are not 2 records returned with column1 being identical.
    Final results should look like this:
         14684940     Pizza Station Inc The     Lafayette     26170      St Marys     304     684-2411     
         15123161     Chris Test     554 Easy St n 43333      Columbus     614     555-5555     
         15123162     Chris Test2     5556 Easy St     43333     Columbus     614     555-5151     2553304
    Thanks in advance for the assistance.

    Hello,
    Try:
    SELECT  abnr, namn, ADR,  boxpnr,  boxort,RIKTNR,  TELNR,tigilopnr
      FROM (
    SELECT tiab.abnr abnr, tiab.namn namn, (CAST(tiab.GATUNR||' '||tiab.gata AS VARCHAR2(254))) ADR, tiab.boxpnr boxpnr, tiab.boxort boxort,
    (CAST(tiab.RIKTNRDISPLAY AS VARCHAR2(254))) RIKTNR, (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) TELNR,
    DECODE((select count(tior.tigilopnr) from tis.tior where abnr = tiab.abnr and inplnr IN (3797886)),0 ,NULL , 1, tior.tigilopnr, 'N/A') tigilopnr,
    ROW_NUMBER () OVER (PARTITION BY tiab.abnr ORDER BY (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) NULLS LAST) row_num
    FROM tis.tiab
    JOIN tis.tior on tiab.abnr = tior.abnr
    WHERE tior.inplnr IN (3797886))
    WHERE row_num <= 1
    ORDER BY abnr;Or, with your current query:
    SELECT  abnr, namn, ADR,  boxpnr,  boxort,RIKTNR,  TELNR,tigilopnr
      FROM (
    SELECT distinct tiab.abnr abnr, tiab.namn namn, (CAST(tiab.GATUNR||' '||tiab.gata AS VARCHAR2(254))) ADR, tiab.boxpnr boxpnr, tiab.boxort boxort,
    (CAST(tiab.RIKTNRDISPLAY AS VARCHAR2(254))) RIKTNR, (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) TELNR,
    DECODE((select count(tior.tigilopnr) from tis.tior where abnr = tiab.abnr and inplnr IN (3797886)),0 ,NULL , 1, tior.tigilopnr, 'N/A') tigilopnr,
    ROW_NUMBER () OVER (PARTITION BY tiab.abnr ORDER BY (CAST(tiab.TELNRDISPLAY AS VARCHAR2(254))) NULLS LAST) row_num
    FROM tis.tiab
    JOIN tis.tior on tiab.abnr = tior.abnr
    WHERE tior.inplnr IN (3797886))
    WHERE row_num <= 1
    ORDER BY abnr;

  • Remove a row from multiple tables

    Hello,
    I have a form that has what appears to be one table.  Since I needed 30 columns (29 of them are single character fields) I had to use 2 table objects.  Then I needed the ability to add and remove rows.  Adding a row at the end is easy enough.  Deleting a specific row is the problem.  At the moment, I added a third table which has a header row and a item body row.  the body row is a button with the intention of removing that entire row from the large table.  This means it needs to remove the row from all 3 tables.
    My structure is:
    form1
    (Some other flowed subform that doesn't matter for us)
    SubformPersonnel (a flowed subform)
    SubformHeader (a positioned subform)
    TextOverallHeader (text to label the oeverall 3 tables)
    ButtonAddRow (adds a row to the end of all 3 tables)
    SubformPersonnelTable (a positioned subform)
    ContractorTableRemove (a table with 1 column for the Remove button)
    HeaderRow (A hidden row to align the table with the other 2)
    Item (A row with the Remove button)CellRemoveButton (the cell with the remove button and associated JavaScript)
    ContractorTableLeft (a table with the left 15 printed columns)
    HeaderRow
    Contractor (A row of data to be removed when CellButton above is clicked)
    ContractorTableRight (a table with the right 15 printed columns)
    HeaderRow
    Contractor (A row of data to be removed when CellButton above is clicked)
    (Some other flowed subforms that I am not worried about at the moment)
    The 3 tables are aligned so the headers all line up, with no spaces between them.  The body rows then line up and this looks like one large table.  From left to right, they are:
    ContractorTableRemove, ContractorTableLeft, ContractorTableRight
    So Item and Contractor rows are added when ButtonAddRow is clicked in the overall header.  The intial count is set to 8 for each table, so I get 8 rows at startup. The minimum count is set to 1 for each.  I know that each row of each table has the same index number because I filled those into a cell in each table durig the cell's initialize.  This line, in the CellRemoveButton's click event deletes that cell's row in that table:
    this.parent.parent._Item.removeInstance(this.parent.index);
    I have tried all sorts of ways to delete the same row (using same index #) in the other 2 tables: ContractorTableLeft and ContractorTableRight, but don't seem to be getting the correct syntax correct.  I have tried hard coding the references, using .parent as shown below, and also tried using an index of 1 just to try deleting a row with no results.
         this.parent.parent.parent.ContractorTableLeft._Contractor.removeInstance(this.parent.inde x);
    Can someone get me the correct syntax here?
    I have seen examples of putting a hidden delete button on each table and clicking that, but I am concerned that it will get in the way of the tables on either side of the table it is in.  I reeally want to just reference the row and remove it so I can avoid any problems these additional delete problems may cause.
    I have copied the form to https://acrobat.com/#d=7M8R50rEHf4AaVXppwyKLw

    Thank you, Niall.  Much appreciated!
    The Delete button was more to make sure one could delete these outside a button in the actual row and I see I had the index wrong such that I was deleting the second row and not the first.  I had toyed with using this as a hidden button if I could pass the index to the event's function.
    I had not thought of adding the reference to each row as a variable.  It seems to work very well.
    For future reference to others, here is the code from the cellRemoveButton click event:
         // Declare some variables
         var i = this.parent.index;
         var oContractorLeft = ContractorTableLeft.Contractor;
         var oContractorRight = ContractorTableRight.Contractor;
         // Remove this row by accessing its index within the set of 'Item' row instances of the parent table
         _Item.removeInstance(i);
          // Since this table is actually 3 tables, we need to remove the other two table's instances as well.
         // Their index should be the same, so we just need to get their names correct.
         oContractorLeft.instanceManager.removeInstance(i);
         oContractorRight.instanceManager.removeInstance(i);
          // removing the row doesn't trigger calculations in tables in the form's current target (fixed in later versions of Acrobat)
         // force calculations to fire so the ItemIndex field's value is updated according to the remaining row's indexes
         // see http://forms.stefcameron.com/2006/05/20/add-recalculate/
         xfa.form.recalculate(1);
    Again, thank you!
    Karl

  • Removing duplicate rows from SELECT

    Hi, I was wondering if there was any way to remove duplicate rows from a select statement.
    My table looks like this:
    CREATE TABLE CUS_ID_TO_PC_ID (
    CUSTOMER_ID VARCHAR2 (10) NOT NULL,
    PC_ID VARCHAR2 (25) NOT NULL,
    PASSWORD VARCHAR2 (25) NOT NULL,
    REG_DATE DATE,
    PRODUCT_DESC VARCHAR2 (25),
    EXPIRE_DATE DATE,
    SERIAL_NBR VARCHAR2 (12),
    LDAP_USER VARCHAR2 (200),
    COMMENTS VARCHAR2 (2000),
    PC_ID_5_4 VARCHAR2 (25),
    PC_ID_6_0 VARCHAR2 (25),
    PASSWORD_5_4 VARCHAR2 (25),
    PASSWORD_6_0 VARCHAR2 (25),
    PC_ID_6_1 VARCHAR2 (25),
    PASSWORD_6_1 VARCHAR2 (25),
    OPERATING_SYSTEM VARCHAR2 (20),
    STATUS VARCHAR2 (1)
    Basically, I want to retrieve all columns from the table but remove all duplicate variations of
    the pc_id/serial_nbr combinations.
    For example, given this data:
    PC_ID SERIAL_NBR CUSTOMER_NO
    1234567 AAA C345
    1234567 AAA C567
    3333333 BBB C456
    only the 1st and 3rd rows would be returned.
    Any ideas?

    Try something like this:
    select * from your_table yt
    where rowid in (select max(rowid)
    from your_tabel yt2
    where yt2.pc_id = yt.pc_id
    and yt2.serial_nbr = yt.serial_nbr);

  • Need to Remove Duplicate Rows

    I have two tables MEMBER_ADRESS and MEMBER_ORDER. The MEMBER_ADRESS has duplicate rows in it based on MEMBER_ID and MATCH_VALUE. These duplicate ADDRESS_IDs were used in MEMBER_ORDER. I need to remove the duplicates from MEMBER_ADRESS making sure I keep the one with PRIMARY_FLAG = ‘Y’ and update MEMBER_ORDER.ADDRESS_ID to the MEMBER_ADRESS.ADDRESS_ID that I kept.
    I am on 11gR1
    Thanks for the help.
    CREATE TABLE MEMBER_ADRESS
      ADDRESS_ID               NUMBER,
      MEMBER_ID                NUMBER,
      ADDRESS_1                VARCHAR2(30 BYTE),
      ADDRESS_2                VARCHAR2(30 BYTE),
      CITY                     VARCHAR2(25 BYTE),
      STATE                    VARCHAR2(2 BYTE),
      ZIPCODE                  VARCHAR2(10 BYTE),
      CREATION_DATE            DATE,
      LAST_UPDATE_DATE         DATE,
      PRIMARY_FLAG             CHAR(1 BYTE),
      ADDITIONAL_COMPANY_INFO  VARCHAR2(40 BYTE),
      MATCH_VALUE              NUMBER(38) GENERATED ALWAYS AS (TO_NUMBER( REGEXP_REPLACE ("ADDITIONAL_COMPANY_INFO"||"ADDRESS_1"||"ADDRESS_2"||"CITY"||"STATE"||"ZIPCODE",'[^[:digit:]]')))
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (200, 30, '11 Hourse Rd.',
        '58754', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:34:10', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 1158754);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (230, 12, '101 Banks St',
        '58487', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:35:42', 'MM/DD/YYYY HH24:MI:SS'), 'N', 10158487);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (232, 12, '101 Banks Street',
        '58487', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:41:15', 'MM/DD/YYYY HH24:MI:SS'), 'N', 10158487);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (228, 12, '101 Banks St.',
        '58487', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:38:19', 'MM/DD/YYYY HH24:MI:SS'), 'N', 10158487);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (221, 25, '881 Green Road',
        '58887', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:34:18', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 88158887);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (278, 28, '2811 Brown St.',
        '58224', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:36:11', 'MM/DD/YYYY HH24:MI:SS'), 'N', 281158224);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (280, 28, '2811 Brown Street',
        '58224', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:45:00', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 281158224);
    Insert into MEMBER_ADRESS
       (ADDRESS_ID, MEMBER_ID, ADDRESS_1, ADDRESS_2, ZIPCODE, CREATION_DATE, LAST_UPDATE_DATE, PRIMARY_FLAG, MATCH_VALUE)
    Values
       (300, 12, '3421 West North Street', 'x',
        '58488', TO_DATE('08/11/2011 10:56:25', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/12/2011 10:42:04', 'MM/DD/YYYY HH24:MI:SS'), 'Y', 342158488);
    COMMIT;
    CREATE TABLE MEMBER_ORDER
      ORDER_ID    NUMBER,
      ADDRESS_ID  NUMBER,
      MEMBER_ID   NUMBER
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (3, 200, 30);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (4, 230, 12);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (5, 228, 12);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (6, 278, 28);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (8, 278, 28);
    Insert into MEMBER_ORDER
       (ORDER_ID, ADDRESS_ID, MEMBER_ID)
    Values
       (10, 230, 12);
    COMMIT;

    Hi John;
    Sorry I missed your post. Yes sorry about the flag. Please take a look as these before and after sets. I hope this helps. I should have posted this in the begining.
    MEMBER_ORDER (BEFORE)
    ORDER_ID  ADDRESS_ID  MEMEBER_ID
    4       228           12
    10       230           12
    5       230           12
    11       232           12
    12       300           12
    8       278           28
    6       278           28
    3       200           30
    MEMBER_ORDER (AFTER)
    ORDER_ID  ADDRESS_ID  MEMEBER_ID
    4       232           12
    10       232           12
    5       232           12
    11       232           12
    12       300           12
    8       280           28
    6       280           28
    3       200           30
    MEMBER_ADDRESS (BEFORE)
    ADDRESS_ID  MEMBER_ID  ADDRESS_1                    CREATION_DATE             LAST_UPDATE_DATE   PRIMARY_FLAG  MATCH_VALUE
    228         12           101 Banks St.                  8/11/2000 10:56:25 AM     8/12/2005 10:38:19 AM     N     10158487
    230         12           101 Banks St                   8/11/2000 10:56:25 AM     8/12/2006 10:35:42 AM     N     10158487
    232         12           101 Banks Street             8/11/2000 10:56:25 AM     8/12/2007 10:41:15 AM     N     10158487
    300         12           3421 West North Street       8/11/2000 10:56:25 AM     8/12/2011 10:42:04 AM     Y     342158488
    221         25           881 Green Road               8/11/2000 10:56:25 AM     8/12/2011 10:34:18 AM     Y     88158887
    278         28           2811 Brown St.               8/11/2000 10:56:25 AM     8/12/2006 10:36:11 AM     N     281158224
    280         28           2811 Brown Street               8/11/2000 10:56:25 AM     8/12/2011 10:45:00 AM     Y     281158224
    200         30           11 Hourse Rd.                  8/11/2000 10:56:25 AM     8/12/2005 10:34:10 AM     Y     1158754
    MEMBER_ADDRESS (AFTER)
    ADDRESS_ID  MEMBER_ID  ADDRESS_1                    CREATION_DATE             LAST_UPDATE_DATE    PRIMARY_FLAG  MATCH_VALUE
    232         12           101 Banks Street                8/11/2000 10:56:25 AM     8/12/2007 10:41:15 AM     N     10158487
    300         12           3421 West North Street       8/11/2000 10:56:25 AM     8/12/2011 10:42:04 AM     Y     342158488
    221         25           881 Green Road                8/11/2000 10:56:25 AM     8/12/2011 10:34:18 AM     Y     88158887
    280         28           2811 Brown Street              8/11/2000 10:56:25 AM     8/12/2011 10:45:00 AM     Y     281158224
    200         30           11 Hourse Rd.                8/11/2000 10:56:25 AM     8/12/2005 10:34:10 AM     Y     1158754

  • Removing Duplicate Rows from resultSet

    I have a query pulling data from 5 tables in 12 columns. I have rows where all of the data is duplicated with the exception of one date column. How would I go about deleting rows that are duplicates with the exception of this one column? I still need to pull the date from the date column with the Max(date).
    i.e.
    Bob Smith 1 2 3 4 12-Jul-2006
    Bob Smith 1 2 3 4 02-Aug-2006
    Bob Smith 1 2 3 4 21-Jan-2006
    Form this resultset I only want one row
    Thanks.

    this example might be of help.
    SQL> select * from employees;
    YEAR EM NAME       PO
    2001 02 Scott      91
    2001 02 Scott      01
    2001 02 Scott      07
    2001 03 Tom        81
    2001 03 Tom        84
    2001 03 Tom        87
    6 rows selected.
    SQL> select year, empcode, name, position,
      2         row_number() over (partition by year, empcode, name
      3                            order by year, empcode, name, position) as rn
      4    from employees;
    YEAR EM NAME       PO         RN
    2001 02 Scott      01          1
    2001 02 Scott      07          2
    2001 02 Scott      91          3
    2001 03 Tom        81          1
    2001 03 Tom        84          2
    2001 03 Tom        87          3
    6 rows selected.
    SQL> Select year, empcode, name, position
      2    From (Select year, empcode, name, position,
      3                 row_number() over (partition by year, empcode, name
      4                                    order by year, empcode, name, position) as rn
      5            From employees) emp
      6   Where rn = 1;
    YEAR EM NAME       PO
    2001 02 Scott      01
    2001 03 Tom        81
    SQL> Delete From employees
      2   Where rowid in (Select emp.rid
      3                     From (Select year, empcode, name, position,
      4                                  rowid as rid,
      5                                  row_number() over (partition by year, empcode, name
      6                                            order by year, empcode, name, position) as rn
      7                             From employees) emp
      8                    Where emp.rn > 1);
    4 rows deleted.
    SQL> select * from employees;
    YEAR EM NAME       PO
    2001 02 Scott      01
    2001 03 Tom        81
    SQL> if you can post a sample create tables and data it will help us provide you a some solutions.

  • How to remove empty row from rfc table output.

    Hello,
      I am using adaptive rfc and printing table output. The table rows start from 2nd row, the first row being empty. How can I remove the empty first row.
    Here is what I tried.
    wdContext.nodeDataSource().nodeTableOutput().moveNext();
    and
    wdContext.nodeDataSource().nodeTableOutput().moveTo(1);
    Neither of them worked. Any clue is appreciated.
    Srinivas

    IWDNodeElement first = wdContext.nodeDataSource().nodeTableOutput().getElementAt(0);
    wdContext.nodeDataSource().nodeTableOutput().removeElement(first);
    Armin

  • How to delete the duplicate rows from the table

    Hi,
    I have 2 tbales namely component, component_audit
    For each record in component table there are multiple entries in component_audit table.
    I need to keep the first record and delete the others from the component_audit table
    say for example
    select a.component_id,a.dt_ti_stamp,a.component_name,a.column_before,b.comments from component_audit a,component b where a.component_id=b.component_id
    ( on the above result set only I shold apply the actual delete query )
    PLease help me in this regards.
    Thanks.

    delete from component_audit a where dt_ti_stamp not in (select
                                            min(b.dt_ti_stamp)
                                       from
                                            component_audit b
                                       where
                                            a.component_id = b.component_id)

  • Remove Duplicate Rows from Left Outer Join

    Hi All,
    I am new to Oracle..I have two tables as follow:
    TableA(EmpID, Empname)
    TableB(EmpID, DeptID, DeptName). A employee can work in multiple dept.
    table A has 1 row as EmpID 1 and TableB has two rows for EmpID 1.
    I have a search page which takes dept ID as parameter and return employee name...Dept ID is not mandatory feld for Search. If DeptID is passed it should return the employee who belongs to that Dept otherwise it should return 1 employee..
    Now I have used as follow:
    :IN_DEPTID is passed as parameter
    Select EmpName from TableA Left Join tableB on a.EmpID = B.EmpID
    WHERE
    CASE WHEN :IN_DEPTID IS NULL
    IN_DEPTID IS NULL
    ELSE|
    DEPTID = :IN_DEPTID
    Now problem is when Dept ID is passed it correctly returns a row but if no deptid is passed it returns 2 rows but i want ony one row as there is only one employee.
    Please help;
    Edited by: user10239708 on 10 Sep, 2008 12:24 AM
    Edited by: user10239708 on 10 Sep, 2008 12:28 AM

    Try this
    Select
    from
         tableA a
    where
         (exists (select 1 from tableB b where a.empid = b.empid and deptid = :IN_DEPTID )
         or
         :IN_DEPTID is null) you database design is not good you should keep the emp, department mapping in different table.
    Regards
    Singh

  • Identifying and reporting Duplicate rows from table

    I want to fetch all the duplicate row from the table and need to report all of it.
    I am trying to run the below query but and not getting the expected output. Please help me.
    Query
    SELECT * FROM ADDT_RPT_REQ A WHERE
    TRIM(A.EMAIL_ADDR) IN
    (SELECT TRIM(EMAIL_ADDR) FROM ADDT_RPT_REQ B
    WHERE TRIM(B.EMAIL_ADDR) = TRIM(A.EMAIL_ADDR)
    AND A.ph_num IN
    (SELECT PH_NUM FROM ADDT_RPT_REQ B
    WHERE TRIM(A.PH_NUM ) = TRIM(B.PH_NUM)
    There are in all 7 columns in the table where id is Unique Id.
    The expected output is something like.
    FST_NAME     LAST_NAME     EMAIL_ADDR     WORK_PH_NUM     ROW_ID     LAST_UPD     BU_ID
    VALERIE     HALL     [email protected]     7819370177     2-21N-4312     31-AUG-04     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     2-21N-4327     29-JAN-04     0-R9NH
    VALERIE     HALL     [email protected]     6034272034     2-21N-4309     04-APR-03     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     2-21N-4317     04-APR-03     0-R9NH
    VALERIE     HALL     [email protected]     8563748820     2-21N-4329     31-AUG-04     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     2-21N-4319     04-APR-03     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     2-21N-4326     04-APR-03     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     2-21N-4324     04-APR-03     0-R9NH
    VALERIE     HALL     [email protected]     8604237395     2-21N-4330     31-AUG-04     0-R9NH
    VALERIE     HALL     [email protected]     7819373731     2-21N-4314     31-AUG-04     0-R9NH
    VALERIE     HALLORAN     [email protected]     6194771101     2-21N-4331     31-OCT-05     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     2-21N-4316     04-APR-03     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     2-21N-4321     04-APR-03     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     7-1W4N-293     15-MAY-04     0-R9NH
    VALERIE     HALL     [email protected]     2032341604     2-21N-4307     31-AUG-04     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     2-21N-4325     04-APR-03     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     2-21N-4315     29-JAN-03     0-R9NH
    VALERIE     HALL     [email protected]     7819373737     7-1W4N-291     15-MAY-04     0-R9NH
    VALERIE     HALLORAN     [email protected]     6194771101     2-21N-4332     31-OCT-05     0-R9NH
    VALERIE     HALL     [email protected]     6038885349     2-21N-4310     31-AUG-04     0-R9NH
    VALERIE     HALL     [email protected]     7819373737324     2-21N-4328     31-AUG-04     0-R9NH
    VALERIE     HALL     [email protected]     7819370177324     2-21N-4313     31-AUG-04     0-R9NH

    Hi again!
    Try that:
    SELECT rowid, fst_name, last_name, email_addr, work_ph_num, row_id, last_upd, bu_id
    FROM ADDT_RPT_REQ A
    WHERE rowid > (SELECT MIN(rowid)
                   FROM ADDT_RPT_REQ B
                   WHERE B.fst_name = A.fst_name
                     AND B.last_name = A.last_name
                     AND B.email_addr = A.email_addr
                     AND B.work_ph_num = A.work_ph_num
                     AND B.row_id = A.row_id
                     AND B.last_upd = A.last_upd
                     AND B.bu_id = A.bu_id);This query should show you all duplicate rows. Use the rowid and DELETE to get rid of these rows.
    DELETE FROM addt_rpt_req A
    WHERE rowid IN (SELECT rowid
                    FROM   (SELECT rowid, row_number() OVER (PARTITION BY fst_name, last_name, email_addr, work_ph_num, row_id, last_upd, bu_id
                                                             ORDER BY row_id) dup
                            FROM addt_rpt_req)
                            WHERE dup > 1);Yours sincerely
    Florian W.
    Edited by: Florian W. on 17.06.2009 14:17

  • Deleting Rows From A Table After Running a Report

    I've created a report that inserts rows into a table on the asp page then calls a BI Publisher report to display the data. After running the report in BI Publisher I need to delete the rows from the table that had just been inserted. How is the best way to go about this in BI Publisher?

    The best way I know of would be to use an "afterReport trigger".
    An afterReport trigger fires after the XML output has been generated.
    Thanks,
    Bipuser

  • Trick to remove duplicate entries from tables ?

    hi.
    i have 53tables which are having duplicate entries and names of all 53 tables r listed in top_t table ?
    can any1 provide me solution to show and if possible ask for remove of those duplicates entries from each table if required ?
    daily i am removing duplicates manually ....its too tedious now !
    can any1 help me out ?

    Well, I suppose if the duplication is such that
    SELECT DISTINCT * FROM tablename;gives you the required result, then you could have a procedure that made a copy of the table, deleted/truncated the original, then inserted the distinct values back into it.
    In 10g you could even use flashback to avoid the temp copy - but it also means you can't use TRUNCATE so whether it's any more efficient I'm not sure. But just for fun and since it's urgent:
    CREATE OR REPLACE PROCEDURE dedupe_table
        ( p_table_name user_tables.table_name%TYPE )
    IS
        k_start_timestamp TIMESTAMP := SYSTIMESTAMP;
    BEGIN
        SAVEPOINT start_of_dedupe;
        BEGIN
            EXECUTE IMMEDIATE 'DELETE ' || p_table_name;
        EXCEPTION
            WHEN OTHERS THEN
                ROLLBACK TO start_of_dedupe;
                RAISE_APPLICATION_ERROR
                ( -20000
                , 'Error deleting ' || UPPER(p_table_name) ||
                   CHR(10) || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE
                , TRUE );
        END;
        BEGIN
            EXECUTE IMMEDIATE
            'INSERT INTO ' || p_table_name ||
            ' SELECT DISTINCT * FROM ' || p_table_name || ' AS OF TIMESTAMP :b1'
            USING k_start_timestamp;
        EXCEPTION
            WHEN OTHERS THEN
                ROLLBACK TO start_of_dedupe;
                RAISE_APPLICATION_ERROR
                ( -20000
                , 'Error repopulating ' || UPPER(p_table_name) ||
                   CHR(10) || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE
                , TRUE );
        END;
    END dedupe_table;
    SQL> select * from wr_test;
          COL1 C C
             1 A B
             1 A B
             2 C D
             2 C D
    4 rows selected.
    SQL> BEGIN
      2      dedupe_table('WR_TEST');
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select * from wr_test;
          COL1 C C
             1 A B
             2 C D
    2 rows selected.I make no claims for robustness, efficiency or human safety.
    Edited by: William Robertson on Sep 24, 2009 7:12 PM

  • How to update duplicate row from table

    Hi,
    how to update duplicate row from table?
    First to find duplicate row then update duplicate row with no to that duplicate row in oracle.
    can you give me suggestion on it?
    Thanks in advance.
    your early response is appreciated...

    In order to find a duplicate row, see:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1224636375004
    (or search this forum, your question has been asked before)
    In order to update it, just create and use an Oracle sequence, have it start and increment at a value that doesn't exist in your table.
    If that doesn't get you going, post some CREATE TABLE + INSERT INTO statements, and the results you want from them, in other words: a complete testcase.

  • Duplicate rows from table

    i have a table A suppose it has 3 columns
    id name sal
    ==========
    1 A 100
    1 A 100
    2 B 200
    2 B 200
    2 B 200
    3 C 300
    I want to find duplicate rows from the above table without passing any column in to the where clause .
    please help me to find out this query.

    maybe you should try the database forum...

Maybe you are looking for

  • Can't move icons in itunes APPS only whole pages move.

    In the last IOS 6.? I could log my iphone into itunes, go to the iphone APPS and there I could move single apps or even whole pages around to get them like I wanted. In iOS 7 trying the same situaltion I was only able to move whole pages around. When

  • KLH1 - Which table holds the data?

    Hi, I'm looking for the table that holds the "Activity Type Groups" that are created under transaction KLH1. Any ideas where I can find this info? Thanks,

  • How to get the column index of the selected column

    Hi All, I have a dynamically populated advanceddatagrid. Iam trying to edit any column of a particular row. In my as file im able to get the row index using selecteditem property. But I need to get the column Index and the updated value of the column

  • Convert JPanel to buffered Image

    Hi, i have a JPanel,I override the paintComponent() method to do a lot of painting. the size of this panel is about 2500 X 2500 i want to convert it to a buffered image, but i dont get image of total panel, but only the image of what is displayed on

  • Can't fit iTunes window in monitor

    I ugraded to iTunes 11.0.3 today and am having some odd behavior in the viewer. Currently cannot access lower right corner of viewer to control size of viewer window. I have toggled between mini viewer / standard & full screen. But still can't grab l