SQL to update two columns in a TABLE2 from TABLE1

I know it's a simple question for some of you, but I am new to SQLs, so please help...

I have two tables, TABLE1 and TABLE2 as below, the two tables contains more records 50million then:
SELECT * FROM TABLE1.
&&&&&&&&&&&&&&&&&&&&&&&&&&&
ID                        BUS_FID                WORKID                  STATIONID                  
---------------------- ---------------------- ---------------------- ---------------------- 
28400000117234         245                    13461428.25           16520877.8             
28400000117513         403                    13461428.25           16520877.8             
28400000117533         423                    13461428.25           16520877.8             
28400000117578         468                    13461428.25           16520877.8             
28400000117582         472                    13461428.25           16520877.8             


SELECT * FROM TABLE2.
&&&&&&&&&&&&&&&&&&&&&&&&&&&
BUS_FID                    ID                 TRPELID                RELPOS                 WORKID                 STATIONID                
---------------------- ---------------------- ---------------------- ---------------------- ---------------------- ---------------------- 
114                    28400000117658         28400000035396         23.225                                                               
115                    28400000117659         28400000035396         23.225                                                               
116                    28400000117660         28400000035396         23.225                                                               
117                    28400000117661         28400000035396         23.225                                                               
118                    28400000117662         28400000035396         23.225                                                               
119                    28400000117663         28400000035396         23.225                                                               
120                    28400000117664         28400000035396         23.225                                                               
121                    28400000117665         28400000035396         23.225                                                               
122                    28400000117666         28400000035396         23.225                                                               
123                    28400000117667         28400000035396         23.225                                                               
124                    28400000117668         28400000035396         23.225                                                               
125                    28400000117669         28400000035396         23.225                                                               
126                    28400000117670         28400000035396         23.225    
Now, I tried to use the following SQL to update the columns ID of WORK & STATIONID in TABLE2 but failed. BUS_FID in the two tables have been UNIQUE indexed and they can be used as primary keys to join these two tables.
UPDATE (
  SELECT  p.WORKID px,
          p.STATIONID py,
          p.BUS_FID pid,
          temp.WORKID tempx,
          temp.STATIONID tempy,
          temp.BUS_FID tempid
    FROM  TABLE1 temp, 
          TABLE2 p
    WHERE pid = tempid
)
  SET px = tempx,
      py = tempy;

COMMIT;
with above code, Oracle gave following errors:
SQL Error: ORA-00904: "TEMPID": invalid identifier
00904. 00000 -  "%s: invalid identifier"
Can someone help me fix it? Thank you ~ ~ ~
BTW, both two tables contains documents more than 50 million. So, if you have a better SQL to perform the same task, please let me know!

Appreciated your help in advance.

Alias cannot be used in the query (sub-) where they are defined.

Concerning

Etbin

Tags: Database

Similar Questions

  • Update multiple columns from multiple tables in a single UPDATE request

    Hello

    I'm trying to figure if I'm heading in the right direction.

    I want to update multiple columns from multiple tables in a single UPDATE request. Also, I would like to update multiple columns in a table from the tables.

    Scenario 1

    UPDATE Table2, Table 3
    SET T2.Column1 = T1.Column1 
    ,T2.Column2 = T1.Column2
    ,T3.Column2 = T1.Column2
    FROM Table1 T1, Table2 T2, Table3 T3
    WHERE T1.id = T2.id
    and T1.id = T3.id
    
    

    Scenario 2

    UPDATE Table3
    SET T3.Column1 = T1.Column1 
    T3.Column2 = T1.Column2
    ,T3.Column3 = T2.Column3
    ,T3.Column4 = T2.Column4
    FROM Table1 T1, Table2 T2, Table3 T3
    WHERE T3.id = T1.id
    and T3.id = T2.id
    
    

    Hello

    For scenario 1, you must write separate instructions UPDATE table2 and table3.

    To guard against someone else change one of these tables while you act so you can copy all relevant data in a global temporary table and update this global temporary table table3.

    ENGAGE only when two tables have been changed.

    You can write a procedure or an INSTEAD OF trigger to do all this.

    For scenario 2, you can reference many tables that you need when new table3.  It might be more efficient and simpler to use the MERGER rather than UPDATED.  For example:

    MERGE INTO table3 dst

    WITH THE HELP OF)

    SELECT t1.id

    t1.column1

    t1.column2

    t2.column3

    t2.column4

    FROM table1 t1

    JOIN table2 t2 ON t1.id = t2.id

    )             src

    WE (dst.id = src_id

    WHEN MATCHED THEN UPDATE

    SET dst.column1 = src.column1

    dst.column2 = src.column2,

    dst.column3 = src.column3,

    dst.column4 = src.column4,

    ;

  • How to update exists column on the table with the exact number and auto increment

    Hello

    I have a table with more than 10 million rows and there is a column called 'number_zaq', I want to update this column on line frist from 2000 and + 1 for the next all ranks.

    Update your_table

    Set number_zaq = rownum + 2000-1;

  • SQL query * I want to insert a file column in the other table based on two columns

    I want to insert a column records to another table based on two columns

    the query below does not work

    insert into def_ver_lnki_p (job_name)

    Select def_job.job_name

    from def_job where def_job.job_id = def_ver_lnki_p.job_id and def_job.table_id = def_ver_lnki_p.table_id;

    Just to correct sql

    Update

    def_ver_lnki_p define job_name =)

    Select def_job.job_name

    of def_job

    where def_job.job_id = def_ver_lnki_p.job_id

    (and def_job.table_id = def_ver_lnki_p.table_id);

  • How to update a record, if it is a composite key (primary key is based on two columns) in the OPS? page?

    Hello

    Actually I got to know this update of a record must be made when the primary key is based on two columns.

    Previously, I used SPEL for a column. It was working fine.

    But I came to know that regardless of the folder I try to update, it was the update page is coming up with the first combination of the record.

    As if RC 131

    RC 124

    RC 125 are the records.

    If I click on update of RC 124 also, the update page is coming up with RC 131 values as it is the first.

    So I understand that the SPEL should be based on two parameters, because it is a composite key.

    How to do?

    Please let me know if you don't understand the problem.

    Thank you.

    Wow!

    I got it.

    Thank you brothers, always a hope that you could help me

  • update of two columns at once

    HI can update us two columns at once by the regular update by mentioning two where clauses with respect to columns

    The where clause decide which set of lines will be updated.
    For example, if the set of rows is not the same for your two columns you must use two sentences--update.
    If the rowset is the same for your two columns you can use a single update statement (but then the where clause will be the same).

    Published by: 87076 on 31.01.2011 02:52

  • Need add/update two records on click on the create/update button

    I have a table with 5 columns

    1 ID - primary key

    2 name

    3. address

    4 CARB

    5 KADER

    Now whenever I do an insert in this table to this table I have to add two rows, as shown below:

    1st row - (name1, Add1, 717, 717)

    2nd place - (name1, Add1, 515, 515)

    Name and address values are entries of the screen and the CARB & KADER values are fixed (717 or 515). So for each click on the button create two records needs to be inserted.

    Even when I update to say record particular Carb - 717 & kader-717, I must also update other file too Carb-515 & kader-515. For each click on the update button, so I need to update two records.

    Please tell me as to how I will do this

    Hello

    Why do you not use insert manual and update according to your requirement process?... Gives 'Never' for automatic processing of the DML and try to create a manual process (PL/SQL blocks) and give the condition.

    Thank you

    Lacombe

  • Can we use two columns AS a command

    Dear all,

    Please suggest

    I have two columns of different table and I want to make a general query selection of values in a table based on one exact string of others. Please find the following query:

    Select a.col1, b.col2
    FROM table1, table2 b
    where a.clo3 like b.col4;

    Now a.col3 values can be like "asbd %" or "qw %" or "% zx.
    where, as in b.col4 it will be asbd or qw or zx.

    Please suggest what I would do.

    Thanks in advance.
    Ankit Rana

    Hi, stone.

    Yes, you can use LIKE this way.

    Do not forget that AS is asymmetric:

    x LIKE y
    

    is usually not the same as

    y LIKE x
    

    because wildcard characters ('%' and '_') have a special meaning in the right operand, which is the expression that comes after LIKE.

    Anky rana says:
    Dear all,

    Please suggest

    I have two columns of different table and I want to make a general query selection of values in a table based on one exact string of others. Please find the following query:

    Select a.col1, b.col2
    FROM table1, table2 b
    where a.clo3 like b.col4;

    Now a.col3 values can be like "asbd %" or "qw %" or "% zx.
    where, as in b.col4 it will be asbd or qw or zx.

    So, it seems that you have to reverse the operands of TYPE:

    where   b.col4  like a.clo3;
    

    By the way, it's a matter of SQL, so a better forum for that would be the [SQL and PL/SQL forum | http://forums.oracle.com/forums/forum.jspa?forumID=75].

  • Validation of feature templates ADF - how to validate two columns using a query?

    Hello

    I'm trying to implement a validation for one of the fields in an ADF entity object. The logic is essentially as follows:

    database has a table - TABLE1 with columns COL1 and COL2 - two columns also exist on the TABLE2.

    When the user enters a value for create or update values TABLE1, before user could save I need to validate the following:

    This combination column1 and column2 entry corresponds to a line of TABLE2. (basically, they must exist as a line of TABLE2).

    I don't know how to do this with my current version of JDev (10.1.3.4), but I hope that it is possible.

    Thanks in advance.

    You can write a validator method at EO level that uses a viewObject with two binding settings to find the specific row in the other table.

  • Update one column of the other

    Hi guys,.

    I have two columns in a table, FIRSTNAME and LASTNAME. Currently, the firstname and lastname appear in the column "Firstname". I would separate the name of this column and insert in the "LASTNAME" column

    For example, here is what I currently have:

    Line: -.

    First name last name

    Peter Andre
    James Dean
    Men watch
    Jenna Klare
    James Smith
    Tina Adams
    Blair Witch


    Currently, my "Lastname" column is empty. I want to update the table to insert lastname in the "First NAME" field in the "LASTNAME" column, so the output will look like:

    First name last name
    Peter Andre
    James Dean
    Men watch
    Jenna Klare
    James Smith
    Tina Adams
    Blair Witch

    Help, please.
    Thanks in advance.

    Hello

    Maybe this,.

    SQL> with t As(Select 'Peter Andre' Name From Dual union all
      2            Select 'James Dean' Name From Dual union all
      3            Select 'Watch Man' Name From Dual union all
      4            Select 'Jenna Klare' Name From Dual union all
      5            Select 'James Smith' Name From Dual union all
      6            Select 'Tina Adams' Name From Dual union all
      7            Select 'Blair Witch' Name From Dual)
      8  SELECT regexp_substr(Name,'[^ ,]+' ) First
      9       , regexp_substr(Name,'[^ ,]+$') LastName
     10    FROM t;
    
    FIRST                                        LASTNAME
    -------------------------------------------- --------------------------------------------
    Peter                                        Andre
    James                                        Dean
    Watch                                        Man
    Jenna                                        Klare
    James                                        Smith
    Tina                                         Adams
    Blair                                        Witch
    
    7 rows selected
    

    or

    SQL> with t As(Select 'Peter Andre' Name From Dual union all
      2            Select 'James Dean' Name From Dual union all
      3            Select 'Watch Man' Name From Dual union all
      4            Select 'Jenna Klare' Name From Dual union all
      5            Select 'James Smith' Name From Dual union all
      6            Select 'Tina Adams' Name From Dual union all
      7            Select 'Blair Witch' Name From Dual)
      8  SELECT Substr(Name,1,Instr(Name,' ',1)-1) First
      9       , Substr(Name,  Instr(Name,' ',1)+1) LastName
     10    FROM t;
    
    FIRST                                        LASTNAME
    -------------------------------------------- --------------------------------------------
    Peter                                        Andre
    James                                        Dean
    Watch                                        Man
    Jenna                                        Klare
    James                                        Smith
    Tina                                         Adams
    Blair                                        Witch
    
    7 rows selected
    

    Kind regards
    Christian Balz

    Published by: Christian Balz on 2009-06-17 15:33

  • Validation of a region defined as a QUERY SQL type (updated report)

    Hello

    I am trying to perform validation on a region defined as type of QUERY SQL (editable report). The report has two columns.
    One of the columns is a Select list and I want to make sure that the user can select the same value twice
    in the report. For example, if the selection list has 5 values A, B, C, D, E, I don't want a user to be able to select
    B twice in the report. Will it use javascript to perform validation? If Yes, could someone provide some guidance on
    where to embed the javascript? Are there other alternatives than javascript? I create an element that came from a sql query
    counts the number of lines where the value of the column is the same. I then used the item in my validation logic. The problem with this logic
    is that a user can enter the same value and it is not until the 3rd attempt to select the same value that the validation works using the number of lines which is why I think that I need to somehow capture the value of the selection list when a user selects and then compare it to what is already in the database column Select.

    I hope that my question and explanations are clear.

    Thanks in advance for your help,

    Michael

    Hello

    This can be managed using javascript or a validation of the page. Here is an example of use of javascript: [http://htmldb.oracle.com/pls/otn/f?p=267:7]

    To do this, I have:

    1 - a model of button which does not send the page but just runs javascript. The model will depend on your theme, but should include:

    <a href="#BUTTON_ATTRIBUTES#">#LABEL#</a>
    

    If #BUTTON_ATTRIBUTES # appears on the template, delete it as we need it only once. You must create a new button model based on a copy of your existing across models, shared components. Normally, he would show href = "" #LINK # "-we do not want that this would become doSubmit('buttonname')." If your model does not use tags for buttons, you might need to create one from scratch.

    2 - I have updated the button on my page to use this template and then assign the setting button attributes:

    javascript:check();
    

    3. in the header of the HTML page, I added:

    <script type="text/javascript">
    function check()
    {
     var e = 0;
     var f = document.getElementsByName("f02");
     var k1;
     var k2;
     var v1;
     var v2;
     if (f)
     {
      for (k1 = 0; k1 < (f.length - 1); k1++)
      {
       v1 = f[k1].value;
       for (k2 = (k1 + 1); k2 < f.length; k2++)
       {
        v2 = f[k2].value;
        if (v1 == v2)
        {
         e = 1;
        }
       }
      }
     }
     if (e > 0)
     {
      alert("Duplicates found!");
     }
     else
     {
      doSubmit("SUBMIT");
     }
    }
    </script>
    

    In this example, SUBMIT is the name of the button and "f02" is the name attribute of the select list items that we want to check - change these needs by your page.

    Now, when the Submit button is clicked, instead of directly submit the page, the javascript function is called. This function loops through each selection list and gets its value. Then, he compared it to the remaining items. If there is a match, the e flag is set to 1. After all the items have been verified, if e is not 0, then a message appears. Otherwise, the page is sent.

    Andy

  • iBooks/iPad two columns per page

    Since this morning after an update to the iPad, iBooks is showing the book pages in two columns instead of a full page, from left to right.  How can I change this back to a page on the screen?

    I saw that too. Stupid solution. Increase your font a to the top of the smallest.

    The smaller police apparently goes into two columns.

  • SQL monitor help with column of chronology

    monitor_test.jpg

    In the report attached to sql, in the timeline column means the whole last 3 began simultaneously and hash join is the first exploited who started?

    my understanding is 'index range scan' should start first and give the data to "Single Partition range". Only once this step completed, he should 'TABLE ACCESS Full'. Isn't this correct?

    Thanks for your time!

    Your description is correct - and I think that you just have to allow some defects in the rounded, graphic display of errors and inconsistencies in what is "the order of execution.

    If it is still possible, you can watch dbms_sqltune.report_sql_monitor output text () as numbers COULD clarify the sequence - on the other hand, the granularity of the timer is not very fine.

    You may find that the chronology of hash join begins before the access times two table - which highlights the problem of "means to launch an operation."  The subroutine "do a hash join" must begin before the two tablescans, on the other hand the mechanism 'return rowsource to parent' cannot start until after the second table access began to return the hash join lines.

    Another sign of the available seeds, of course, is that the select statement does not seem to have started until a few seconds after the hash join has started!

    Concerning

    Jonathan Lewis

  • using outer joins if the two column is null? Use only (+)

    Hi all

    create the table xxc_tr_num (tl_number number, tr_no number tl_no_id);

    insert into xxc_tr_num values (123,100,222);

    insert into xxc_tr_num values (124,100,333);

    create the table xxc_od_tab (tl_number number, tl_id number);

    insert into xxc_od_tab values (123,001);

    insert into xxc_od_tab values (null, null);

    create table xxc_oth_tab (name varchar2 (10), number of tl_id);

    insert into xxc_oth_tab values('abc',,001);

    insert into xxc_oth_tab values (null, null);

    Wait it out put

    tr_no tl_no_id name

    100 222 abc

    100 333

    using outer joins if the two column is null? use only please of outer joins

    And I tried to use outer joins on both tl_id column but not get values and I use have County (tr_no ) > 1

    Rajesh123 wrote:

    Thank you Kiss it is not possible to use having clause?

    You need to understand the functioning of the group. If you will not be asked this question.

    Check this box

    SQL> select tr_no,
      2         tl_no_id,
      3         count(*)
      4    from xxc_tr_num a,
      5         xxc_od_tab b,
      6         xxc_oth_tab c
      7   where a.tl_number = b.tl_number(+)
      8     and b.tl_id = c.tl_id(+)
      9   group
     10      by tr_no
     11       , tl_no_id;
    
         TR_NO   TL_NO_ID   COUNT(*)
    ---------- ---------- ----------
           100        333          1
           100        222          1
    

    See what returns the count? You have grouped according to TR_NO and TL_NO_ID. You must take into consideration the TL_NO_ID just put COUNT (TR_NO) does not increase the NUMBER of the whole group. To get the NUMBER on the whole group, I used the analytical function and did. Like this, see the number of the analytical function here

    SQL> select tr_no,
      2         tl_no_id,
      3         count(*),
      4         count(*) over(partition by tr_no)
      5    from xxc_tr_num a,
      6         xxc_od_tab b,
      7         xxc_oth_tab c
      8   where a.tl_number = b.tl_number(+)
      9     and b.tl_id = c.tl_id(+)
     10   group
     11      by tr_no
     12       , tl_no_id;
    
         TR_NO   TL_NO_ID   COUNT(*) COUNT(*)OVER(PARTITIONBYTR_NO)
    ---------- ---------- ---------- ------------------------------
           100        222          1                              2
           100        333          1                              2
    

    So to answer your question, yes you can't do in the HAVING clause...

  • Numbers between two columns

    Hello

    I would like to create sequential numbers between these two columns of the specified table.

    Existing data in the table

    Column1 Column2
    57
    1314
    1819
    2427
    2929

    power required:

    5

    6

    7

    13

    14

    18

    19

    24

    25

    26

    27

    29

    Could someone help me with this please.

    Thank you.

    XQUERY solution:

    with

    data in the form of

    (select 5 Column1, Column2 7 Union double all the)

    Select 13,14 in union double all the

    Select 18,19 Union double all the

    Select 24,27 Union double all the

    Select double 29,29

    )

    Select n

    data,.

    XMLTable)

    "xs:integer ($s) at xs:integer ($e).

    passing of Column1 as "s",.

    Column2 like 'e '.

    columns

    path number n '. »

    )

    /

    N
    ----------
    5
    6
    7
    13
    14
    18
    19
    24
    25
    26
    27

    N
    ----------
    29

    12 selected lines.

    SQL >

    SY.

Maybe you are looking for