Remove duplicates and fix a join table

Oracle 10.2 g

I have two tables and a table of junction between them.

Table_a
name identity
1 TEST
2 OF TEST2
TEST 3

Table_B
ID
1
2
3
4

TableA_TO_B
A_ID b_id
5 5
1 2
3 3

Duplicates could not in table A, but the unique constraint has been accidentally disabled.

So I want to be able to do is to remove all duplicates of table A, and if there is no line in
TableA_TO_B that contain identifiers should be deleted, I want to update this line to refer to the now single
TableA line.

I am able to find duplicates by practice

Select the id of the table_a where rowid > (select min (rowid) in the b table_a where b.SID = b.name)

But after that I'm stuck.

Hello...

There may be a more elegant way to do this, rather than create an intermediate table, but... (note that this is NOT tested and may need some tuning/indexing on the staging table if you operate on large data sets!) :

(1) create a temporary table by storing the ID to keep (and thus the value updated in TableA_B) - Note This code assumes that the folder with the ID (MIN) low will be the value stored in TableA...

create table tmp nologging as
select id,name,min(id) over (partition by name) ID_TO_KEEP
from table_a;

(2) execute the update statement, by changing the values that must be maintained (i.e. no are NOT deduplicated):

update tablea_b ab
set a_id = (select id_to_keep from tmp where id=ab.id);

(3) perform the delete duplicates deleting statement in TableA (NOTE: assumes that you do not have etc. funky foreign key constraints on tables!):

delete from table_a a where EXISTS (select id from tmp where id=a.id and id<>id_to_keep);

I hope that works for you...! ;-)

Tags: Database

Similar Questions

  • Remove duplicate for a single column table

    Hi all

    So I try to work on a problem here. I searched the forums but I did find something that works for me. Here's my problem... I have a chart (conversion to a .csv file) with a lot of lines and columns. Each line is a log for a specific serial number file. The amount of columns is fixed. But, I must create a vi to go through the table and remove the duplicates under the original and create a new table. For example, my table might look like this (I added a header desc for clarity):

    Job, Tech, SN

    1827, SJ, 23827

    1825, SJ, 23827

    1827, SJ, 47384

    1827, SJ, 57483

    1827, SJ, 37473

    1825, SJ, 37473

    But I want a table attached like this:

    Job, Tech, SN

    1827, SJ, 23827

    1827, SJ, 47384

    1827, SJ, 57483

    1827, SJ, 37473

    Can someone help me?

    Thank you

    Ryan

    Here's a version that works if duplicates are not necessarily adjacent. As a side effect, the output array is also sorted by serial number.

  • Remove duplicates and add to collection totals ArrayCollection

    Is there a function that removes duplicates from a table collection and totals a value where duplicates?

    For example Array

    [Name: John, value: 2]

    [Name: Dave, value: 10]

    [Name: John, value: 2]

    [Name: Dave, value: 8]

    [Name: Dave, value: 2]

    [Name: John, value: 1]

    Output should be:

    Name: John value: 5

    Name: Dave value: 20

    Thank you very much - I really need help with this, I can not logic.

    Thank you

    Please try this,

    private void filterData(event: MouseEvent): void {}
    var source: collection ArrayCollection = new ArrayCollection();
    source.addItem ({name: "John", value: 2});
    source.addItem ({name: "Dave", value: 10});
    source.addItem ({name: "John", value: 2});
    source.addItem ({name: "Dave", value: 8});
    source.addItem ({name: "Dave", value: 2});
    source.addItem ({name: "John", value: 1});
       
    var result: collection ArrayCollection = new ArrayCollection();
    var flag: Boolean;
    for (var i: int = 0; i)< source.length;="" i++)="">
    flag = false;
    for (var j int = 0; j< result.length;="" j++)="">
    If (result.getItemAt (j) ['name'] is {source.getItemAt (i) ["name"])}
    result.getItemAt (j) ['value'] is (result.getItemAt (j) ['value'] + source.getItemAt (i) ["value"]);.
    flag = true;
    break;
    }
    }
    If (! flag) {}
    result.addItem (source.getItemAt (i));
    }
    }
    for (var K:: int = 0; k)< result.length;="" k++)="">
    Alert.Show (result.getItemAt (k) ['name'] + '-' + (k) result.getItemAt ["value"]);
    }
    }

  • How can I fix the join table dotted outline style?

    I kept super organized when setting up my styles to table this time. I put as much as possible in the configuration of the tracked table of cell styles for some of the columns and some lines (like subdivisions). The problem with cell styles, is that you cannot set cells of running styles, only around them. So if there is a setting to do at the macro level, I would be really happy. I always get problems with formatting applied when I apply a too large number of styles or substitutions, that's what I'm trying to avoid.

    Here's the problem: table styles are still process my shots at the level of the individual cell. I use dotted in the columns, but there is no seal between the rows. They line you up at the top and at the bottom of each cell. See gray lines in this example (blue dots are bullets, not shots):

    Screen shot 2012-10-02 at 2.28.38 PM.png

    But when I replace the column and redo the outline in the outline palette, they look as expected. Compare the cells highlighted (black) to the existing table style (lines white gray and light):

    Screen shot 2012-10-02 at 2.32.05 PM.png

    Is there a setting somewhere that I'm missing? Any suggestions apart from the hand control?

    Note: I'm in CS6 on Mac 10.6, where it is important.

    In fact, I need cell styles. This is what distinguishes my font, spacing and GREP styles.

    I found the solution today. In the style of table or the table setting, I needed the "race drawing of mark" 'column Strokes in Front. Even if it has been previously set to 'Best joins' and I had no hits for lines or for table borders, was not simply giving priority to my columns dotted.

    Thanks for your reply though!

  • How to remove duplicates from the PL - SQL table?

    Hi gurus,

    I have a PL - SQL table with the following structure
    Authors (SR_NO, Auth_Code, Change_Date, cost)

    This table is filled using a slider. However, this table can have a few lines in double (for column (Auth_Code)
    for example
    SR_NO      Auth_Code       Change_Date                       Cost
    1               A1             14-FEB-09 08.18.47 AM          11.00
    2               A2             14-FEB-09 08.18.56 AM       2839.00
    3               A1             15-FEB-09 08.00.02 AM      1299.00
    4               A1             15-FEB-09 07.00.00 AM        789.00
    5               A3             14-FEB-09 08.18.56 AM        312.00
    6               A4             14-FEB-09 08.19.02 AM        233.00
    I need to get the above result set select the separate lines of Auth_Code including the Change_Date is maximum (and store in another PL - SQL table for treatment later or even the removal of this table will be also!)

    of the data A1 is duplicated and a maximum Change_Date above = 15 February 09 08.00.02 AM.
    Where my PL - SQL Table that results must have given below
    SR_NO      Auth_Code       Change_Date                       Cost
    2               A2             14-FEB-09 08.18.56 AM       2839.00
    3               A1             15-FEB-09 08.00.02 AM      1299.00
    5               A3             14-FEB-09 08.18.56 AM        312.00
    6               A4             14-FEB-09 08.19.02 AM        233.00
    I'm not very aware of the PL - SQL tables and there is no chance to change the existing cursor that fills the data in this table PL - SQL.
    I guess that I need to compare each record of PL - SQL table with others, but do not know how to do this.

    Could you please help?

    Hello

    Like this?:

    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    
    SQL>
    SQL> with data as(
      2  select 1 as SR_NO, 'A1' as Auth_Code, to_date('14-FEB-09 08.18.47', 'dd-mon-yy hh24:mi:ss') as change_date,    11.00 as cost from dual union all
      3  select 2 as SR_NO, 'A2' as Auth_Code, to_date('14-FEB-09 08.18.56', 'dd-mon-yy hh24:mi:ss') as change_date,  2839.00 as cost from dual union all
      4  select 3 as SR_NO, 'A1' as Auth_Code, to_date('15-FEB-09 08.00.02', 'dd-mon-yy hh24:mi:ss') as change_date,  1299.00 as cost from dual union all
      5  select 4 as SR_NO, 'A1' as Auth_Code, to_date('15-FEB-09 07.00.00', 'dd-mon-yy hh24:mi:ss') as change_date,   789.00 as cost from dual union all
      6  select 5 as SR_NO, 'A3' as Auth_Code, to_date('14-FEB-09 08.18.56', 'dd-mon-yy hh24:mi:ss') as change_date,   312.00 as cost from dual union all
      7  select 6 as SR_NO, 'A4' as Auth_Code, to_date('14-FEB-09 08.19.02', 'dd-mon-yy hh24:mi:ss') as change_date,   233.00 as cost from dual)
      8  select * from data d where change_date = (select max(change_date) from data d2 where d.auth_code = d2.auth_code);
    
         SR_NO AUTH_CODE CHANGE_DATE       COST
    ---------- --------- ----------- ----------
             2 A2        14/02/2009        2839
             3 A1        15/02/2009        1299
             5 A3        14/02/2009         312
             6 A4        14/02/2009         233
    
    SQL>
    

    Kind regards

  • I have malware TROVI kidnap my new tab defaults, how can I remove it and fix it (I already uninstalled)

    I also removed trovi from the registry and still everytime I open a new tab, it goes to Trovi.com

    Help, please.

    Thank you

    Download. com delinkified J99 is to let the bad guys in my computer. When I did a scan of Malwaresbytes, we found 109 of them, and I had scanned and got own results Sunday. Once Malwarebytes (downloadable for free) removed and quarantined the hijackers, after that re-booting my computer, things seem well, including my tabs. Recommend getting malwarebytes here: edit related to the malware bytes of the site J99, malwarebytes.org and its use. Be sure to remove all other choices of software if you download. When nothing else has worked for me, it made.

  • How to identify and remove duplicates and files in Windows 7 and those who are not the files in Win 7

    I used a program called IntelliMover and think that it flies over the files and unnecessary files.  How can I identify and delete these files?

    If make sure you that the files are not used by some programs or windows, then, the answer is YES.
    Easier would be, just look for duplicates in the folders where the files are not required by Windows or programs.

  • need to remove duplicate rows from a table

    Hi gurus,

    I'm 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)

    DATE OF ATTRIB_26

    ATTRIB_02 VARCHAR2 (100 CHAR)

    PROCESS_TIMESTAMP TIMESTAMP (6);

    now, when I give the command below, it gives error as someone has disabled the constraint accidentally.

    change the table s_evt_act_x S_EVT_ACT_X_P1 enable constraint;

    Error from line 3 in order:

    change the constraint of table s_evt_act_x activate S_EVT_ACT_X_P1

    Error report:

    SQL error: ORA-02437: impossible to validate (OSSTAGE. S_EVT_ACT_X_P1) - primary key violated

    02437 00000 - "can't validate (s.%s) - primary key violated."

    * Cause: attempted to validate a primary key with duplicate values or null

    values.

    * Action: remove duplicates and nulls before enabling a primary

    key.

    You can guide me please with this question.

    Please see

    Script: Remove the duplicate of a Table (Doc ID 31413.1) lines

    How to find or remove the duplicate in a Table (Doc ID 1004425.6) lines

  • Remove duplicates from the oracle table using 2 columns

    Hello

    I need to remove the duplicates of an oracle table based on 2 columns in the table.i tried to remove duplicates using the join, but get the error like sql error ora-00933

    Thank you

    Hello

    Here's one way:

    DELETE FROM table_x

    WHERE ROWID NOT IN)

    SELECT MIN (ROWID)

    FROM table_x

    Col_1, col_2

    );

    I hope that answers your question.

    If this isn't the case, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.

    In the case of a DML operation (for example, REMOVE) the sample data should show what look like the paintings before the DML, and results will be the content of the or the tables changed after the DML.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

  • To check and remove duplicate records

    Hi guys,.

    I have a T1 table where my col_1, col_2, col_3 columns are primary keys and the table is to have a huge volume of data recorded about 200 billion. Before you add the primary key, I need to check if there are duplicates and then delete these records. Who will be fastest way to check, I used below

    Select * from T1

    where rowid in (select rn (INF. Select rowid,

    DENSE_RANK() on ln (score of col1, col2, col3 order by rowid)

    from T1)

    where ln <>1);

    Is there another way using the analytical function can be faster to access the records of 200 billion

    Sven wrote:

    Instead of making a deletion consider to re-create the table using only the unique values. Very often, it's much faster than a delete even if more data is moved, but as always, it depends.

    It would be useful if you know how many lines you have and how duplicates are for example (the number of records is removed).

    Also, you should have a comparable test database, which is not always easy to have with large datasizes are invloved.

    Yes, Sven is quite right, ETG might actually be faster to remove duplicates of the original. But you will need to investigate the volume of data.

    create table T2 as

    Select col1, col2, col3,..., coln - all original columns except rn

    from (select t.*, row_number() on rn (score of col1, col2, col3 order by rowid)

    t)

    where rn = 1

    /

    Then hover over any constraint, etc. and drop T with purge, rename T2 in T.

  • How to join tables and get ppl not in the list of the other table

    Hi, I have 2 tables

    Table (girlscoutid, quarter, point)

    Table b (girlscoutid, fname lname)

    I want to get the names of ppl who didn't sell any point/s for Q4

    girlscoutid agenda quarter
    7771drinks4QS
    9000Tickets4QW
    7771Cookies2QS
    5085books3QF
    3010Tickets3QW
    5085Cookies1QF

    lscoutid fname lname
    7771JennRichochet
    9000LauraWilkins
    5085SallyMae
    3010DoraMcKenzie

    That's what I have, however, I get duplicates and also 7771 appears on the list even if she sold something on the 4th quarter. Any suggestions?

    SELECT fname, lname, a.girlscoutid

    Of a, b

    WHERE a.girlscoutid = b.girlscoutid

    AND the term NOT AS "4Q_";

    Hello

    So, all the information that you want to see figure in table b, but if you want to see it depends on the table has.

    This looks like a job for a semi Join.  Here's a way to do it:

    SELECT b.fname

    b.lname

    b.girlscoutid

    B

    LEFT OUTER JOIN has IT a.girlscoutid = b.girlscoutid

    AND a.quarter NOT AS "4Q_" - or a.TERM, if it is the column

    WHERE a.girscoutid IS NULL

    ;

    What you posted was an INNER join, where the rows of each table are included in the only game that if they have a corresponding row in the other table.

    An OUTER join includes all the rows in a table (table b in this case) if they have a match in the other table.  If a line of b has no corresponding row in a, then all the columns that are supposed to come from table will be NULL in the result set.  Given that the join condition includes = b.girlscoutid a.girlscoutid, this means that the only way to a.girlscoutid can be NULL in the result set is if the b line is included although it has no corresponding line one, which are exactly the lines that we want to display.  (You can try to run the query above with the WHERE clause, deleted, just to see how it works.)

    Alternatively, you can get the desired results by using a subquery NOT EXISTS, a NOT IN subquery or analytical functions.  The semi join, supra, is probably the most effective solution.

  • Remove duplicates in an oracle table

    Hello

    I want to remove duplicates from a table of account

    Contains 2 column Account_id and Account_type

    counts the values in the table are

    Account_id Account_type
    1 GPR
    1 GPR
    1 GPR


    I want only one entry and delete the other entry with Account_Id = 1

    Thank you
    Petri

    One of the ways is...

    delete accounts
    where rowid not in (select max (rowid) of the Group of accounts by account_id, account_type)

    Concerning

  • 3.6.2 the numbers help find and remove duplicates in 2 columns

    Could someone help me please. I run a karaoke business. As you may have guessed I have books with many songs, 64 000 and more than 75% of these songs are duplicates so you can imagine by train to sort. Option 1 I could manually go through my list by removing duplicates or option 2 attempt to find a formula that works save me hours of blind deletion. Is there someone out there who can help? It would be much appreciated thanks.

    Here is a sample of the document I'm working.

    Hi robi.

    Here is a solution of Craig s. Ruddock in this discussion Re: duplicates warning formula

    Formula in B2 (fill down)

    = IF (COUNTIF($A,A) = 1",","duplicate")

    Now sort by column A

    Remove all but one of the "duplicate" lines for each song.

    Kind regards

    Ian.

  • Anyone know if the Adobe Pro 11 program allows you to remove and rebonding of new tables in the existing PDF documents?

    Anyone know if the Adobe Pro 11 program allows allows you to remove and re - paste new tables in the existing PDF documents?

    Hi span Structures.

    Acrobat Pro XI allows to edit/insert text and images, but it is not intended to do some heavy lifting in this Department. And, there is really no way to modify the tables in Acrobat, because they are generally made of individual vector lines that you cannot fill.

    If you have many changes to make, or want to add/remove a table, you better make these modifications in the source application and by recreating the PDF file.

    Best,

    Sara

  • JS: How to remove duplicates in a table?

    JS: How to remove duplicates in a table?

    I guess there's a simple solution...

    Hey!

    Maybe something like this:

    Array.prototype.unique = function (){
        var r = new Array();
        o:for(var i = 0, n = this.length; i < n; i++){
            for(var x = 0, y = r.length; x < y; x++){
                if(r[x]==this[i]) continue o;}
            r[r.length] = this[i];}
        return r;
    }
    

    Use:

    var myArray = ["a","b","c","c","a","d","b","b"];
    alert(myArray.unique());
    

    Hope that helps.

    --

    tomaxxi

    http://indisnip.WordPress.com/

Maybe you are looking for

  • 8600 CN579A more: more than 8600 does not work with Windows 10

    HP has plans to support the more than 8600 on Windows 10, or they will offer a discount on a replacement printer?

  • Help someone please.

    Nice day. Finally I found a cable that can connect to my sansa clip to my office, I thought I would have no problem but I was wrong, I got a new problem with the sansa clip now. I don't know how to put the songs on it. you guys could help me what I h

  • Update of PC Companion by mistake

    Hello. I leave companion pc trying to update itself or I use installer smartphone that download the latest version, the software is TOTALLY Impossible to install the latest version. I always get stupid error that says that there is a fatal error duri

  • apk2bar command line problem

    When you try to build the bar of the APK file and by using command line tools, I get the following error: Error: MANIFEST. MF, invalid value ' ' for the name of the Application I have addedapplication android: name = "bbapp" but it does not solve the

  • Error in the final launch sequence - 500 failure ' ascii' codec can't decode byte 0xc3 in position 111: ordinal not in range (128)

    Hello running an application on a device of Momentis just doesn't work. Here's what I did: -downloaded and installed Momentics -downloaded and installed 10.2 API level (target device is a Z10) -created a new BlackBerry in Momentics application from t