Update with join

Hello Everybody
I have 3 tables in a maxdb 7.6 database
rbarbeitsplanpos key=rbarbeitsplanposid column gewichtung,...
rbaplposausf key=rbaplposausfid columns rbarbeitsplanposid,...
rbqspruefpos key=rbqspruefposid columns rbaplposausfid,gewichtung,...
Now i want to update gewichtung in rbqspruefpos with the value of gewichtung in the corresponding record in rbarbeitsplanpos.
The way to find the correct value is:
From rbqspruefpos with rbaplposausfid into rbaplposausf  
From rbaplposausf with rbarbeitsplanposid to rbarbeitsplanpos
I found this hit:
A simple example of the power of including joins in an Update Statement:
Update Tbl1 set tbl1.field1=tbl2.field2*.10,
from Tbl1 join tbl2 on tbl1.PKfield=tbl2.tbl1FK
This will update all the joined rows in tbl1 to 10% of the values in tbl2.
I code:
update rbqspruefpos set gewichtung =  rbarbeitsplanpos.gewichtung,
from rbqspruefpos
join  rbaplposausf on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid
join rbarbeitsplanpos on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
General error;-5016 POS(73) Missing delimiter: =
This one works without errors:
update rbqspruefpos set gewichtung = (select rbarbeitsplanpos.gewichtung  from rbarbeitsplanpos
join  rbaplposausf on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
join rbqspruefpos on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid)
but all rbqspruefpos.gewichtung are filled with the same value?
The first value found in rbarbeitsplanpos.
Any help welcomed
Best regards
Albert

> I code:
> update rbqspruefpos set gewichtung =  rbarbeitsplanpos.gewichtung,
> from rbqspruefpos
> join  rbaplposausf on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid
> join rbarbeitsplanpos on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
>
>  General error;-5016 POS(73) Missing delimiter: =
>
>
> This one works without errors:
> update rbqspruefpos set gewichtung = (select rbarbeitsplanpos.gewichtung  from rbarbeitsplanpos
> join  rbaplposausf on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
> join rbqspruefpos on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid)
>
> but all rbqspruefpos.gewichtung are filled with the same value?
> The first value found in rbarbeitsplanpos.
Looks like you're doing it wrong.
Subselects need to be enclosed in brackets.
See [Subquery (subquery)|http://maxdb.sap.com/doc/7_6/60/515f3eca2a11d2a97100a0c9449261/content.htm]
Only scalar subselects (these are the ones that by their very structure can only produce zero or one rows in the result set) can omit the brackets.
The database cannot know that there is only one value in this column - you may try and put a aggregation function round it.
regards,
Lars

Similar Messages

  • Oracle Syntax for Update with Join

    Can anyone help with the Oracle Syntax on and update that includes a join?
    This is what I've got:
    Update
    (SELECT a.DOCUMENT_NO
    From DOCUMENT_CONTROL a, DOCNOTEST b
    where a.DOCUMENT_NO = b.DOCUMENT_NO)
    set a.PATH = NULL
    Everything I try leads to another error message. With the current code I'm getting the error message: ORA-00971 a.path invalid identifier.
    I am much more familiar with SQL Server (if you can't tell :) This is the way I would write the above in SQL Server.
    UPDATE DOCUMENT_CONTROL
    Set [Path] = ''
    FROM DOCUMENT_CONTROL
    INNER JOIN DOCNOTEST
    ON DOCUMENT_CONTROL.DOCUMENT_NO=DOCNOTEST.DOCUMENT_NO
    where DOCUMENT_CONTROL.DOCUMENT_NO=DOCNOTEST.DOCUMENT_NO
    Does anyone have any advice for me? Thanks in advance

    Alternate syntax since it seems you're not able to update the join...
    update DOCUMENT_CONTROL a
    set
       a.path = null
    where a.path is not null
    and exists
       select null
       from DOCNOTEST b
       where  a.DOCUMENT_NO = b.DOCUMENT_NO
    );

  • Query tuning - update with join statement

    Hi,
    I have 2 tables (table1 and table 2) with following condition:
    TABLE 1 - Need to selection a column say staus ! = 'C'
    join emp_id and project_id of TABLE1 and TABLE2
    From join I am selecting minimun and maximum of TABLE2.salary and updating TABLE3 respective column.
    Now as per requirement I have to update required column on TABLE2.EMP_ID = TABLE3.EMP_ID
    Following is the query I have written,
    update TABLE3 T3
    set (T3.MIN_salary, T3.MAX_salary) = (
    select min(c.salary), max(c.salary)
    from TABLE2 t2, TABLE1 t1
    where t2.emp_id = t1.emp_id
    and t2.project_id = t1.project_id
    and t1.status != 'C'
    and t2.emp_id = t3.emp_id)
    The above query takes 7 min to update some 8 lakhs records. Can you please suggest some other optimized method to do so?
    Thanks in advance
    Sandeep

    Hi SBH
    Required info for "Please provide oracle version, indexes on the 3 tables and also stats info for the table from user_tables"
    1) Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit
    2) Index is not there on TABLE3 (It is temporary table)
    Composite index on TABLE 1 - column1, column2 - Index name say table1index1
    Composite index on TABLE 2 - column1, column2 - Index name say table2index1
    TABLE_NAME     NUM_ROWS     BLOCKS     DEGREE     INSTANCES     SAMPLE_SIZE     PARTITIONED
    FXO_CFW     11767341     144930     1     1     11767341     NO
    FXO_RSL_STBL               1     1          NO
    FXO_TRN     4917778     230196     1     1     4917778     NO
    execution plan is:
    Execution Plan
    Plan hash value: 3131833900
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | UPDATE STATEMENT | | 789K| 23M| 2397 (3)| 00:00:29 |
    | 1 | UPDATE | TABLE3 | | | |
    | 2 | TABLE ACCESS FULL | TABLE3 | 789K| 23M| 2397 (3)| 00:00:29 |
    | 3 | SORT AGGREGATE | | 1 | 28 | | |
    | 4 | TABLE ACCESS BY INDEX ROWID | TABLE2 | 1 | 17 | 3 (0)| 00:00:01 |
    | 5 | NESTED LOOPS | | 1 | 28 | 12 (0)| 00:00:01 |
    |* 6 | TABLE ACCESS BY INDEX ROWID| TABLE1 | 1 | 11 | 9 (0)| 00:00:01 |
    |* 7 | INDEX RANGE SCAN | IDX_TABLE1INDEX1 | 6 | | 3 (0)| 00:00:01 |
    |* 8 | INDEX RANGE SCAN | IDX_TABLE2INDEX1 | 1 | | 2 (0)| 00:00:01 |
    Thanks for quick response,
    Sandeep

  • Update with join and group by

    Hello All,
    I'm trying to update several colums of a table from a inner join query.
    First a retrieve the rows afected and the values that I need for the update (I call this subquery ED_Query).
    It's important to note that this subquery has a group by and and having clause.
    My first attemp (using the query that work in SQL Server query) fails:
    SQL> update ED_Update
    2 set ED_Update.dtHoraInicioReal = ED_Query.dtHoraInicioReal,
    3 ED_Update.dtHoraFinReal = ED_Query.dtHoraFinReal,
    4 ED_Update.fPorcentajeRealizado = ED_Query.fPorcentajeRealizado
    5 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED_Update
    6 inner join (
    7 select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
    8 MAX(PT.iOrdenEnTrayecto) + 1 as iNumParadas,
    9 MAX(HPP.iOrden) as iOrdenUltimaParada,
    10 MIN(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60)) as dtHoraInicioReal,
    11 MAX(dtHora_LlegadaReal) as dtHoraFinReal,
    12 100 * cast ((MAX(HPP.iOrden) + 1) as float) / cast ((MAX(PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado
    13 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED
    14 left join HISTORICOS_AVANZA.HSAE_HIS_HORAPASOPARADA HPP
    15 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
    16 left join AVANZA.SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
    17 where ED.dtJornada = TO_DATE('14/01/2013', 'DD/MM/YYYY') and ED.iIdExpedicion in (-131076)
    18 group by ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal, ED.dtHoraFinReal
    19 having ED.dtHoraInicioReal <> min(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60))
    20 or ED.dtHoraFinReal <> max(dtHora_LlegadaReal)
    21 ) ED_Query
    22 on ED_Update.iIdExpedicionDiaria = ED_Query.iIdExpedicionDiaria;
    ERROR at line 5:
    ORA-00933: SQL command not properly ended
    The subquery (ED_Query) work fine in Oracle, so I suspect that the problems are when I mix it with the update clause.
    SQL> select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
    2 MAX(PT.iOrdenEnTrayecto) + 1 as iNumParadas,
    3 MAX(HPP.iOrden) as iOrdenUltimaParada,
    4 MIN(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60)) as dtHoraInicioReal,
    5 MAX(dtHora_LlegadaReal) as dtHoraFinReal,
    6 100 * cast ((MAX(HPP.iOrden) + 1) as float) / cast ((MAX(PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado,
    7 ED.dtHoraInicioReal as ED_dtHoraInicioReal, ED.dtHoraFinReal as ED_dtHoraFinReal, ED.fPorcentajeRealizado as ED_fPorcentajeRealizado
    8 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED
    9 left join HISTORICOS_AVANZA.HSAE_HIS_HORAPASOPARADA HPP
    10 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
    11 left join AVANZA.SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
    12 where ED.dtJornada = TO_DATE('14/01/2013', 'DD/MM/YYYY') and ED.iIdExpedicion in (-131076)
    13 group by ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal, ED.dtHoraFinReal, ED.fPorcentajeRealizado
    14 having ED.dtHoraInicioReal <> min(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60))
    15 or ED.dtHoraFinReal <> max(dtHora_LlegadaReal);
    IIDEXPEDICION IIDEXPEDICIONDIARIA INUMPARADAS IORDENULTIMAPARADA DTHORAINI
    DTHORAFIN FPORCENTAJEREALIZADO ED_DTHORA ED_DTHORA ED_FPORCENTAJEREALIZADO
    -131076 5662 406 15-JAN-13
    15-JAN-13 15-JAN-13 15-JAN-13 0
    -131076 5663 406 15-JAN-13
    15-JAN-13 15-JAN-13 15-JAN-13 0
    -131076 5664 406 15-JAN-13
    15-JAN-13 15-JAN-13 15-JAN-13 0
    After reading this forum, I change the query and try the next one:
    SQL> UPDATE
    2 (
    3 select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
    4 MAX(PT.iOrdenEnTrayecto) + 1 as iNumParadas,
    5 MAX(HPP.iOrden) as iOrdenUltimaParada,
    6 MIN(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60)) as dtHoraInicioReal,
    7 MAX(dtHora_LlegadaReal) as dtHoraFinReal,
    8 100 * cast ((MAX(HPP.iOrden) + 1) as float) / cast ((MAX(PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado,
    9 ED.dtHoraInicioReal as ED_dtHoraInicioReal, ED.dtHoraFinReal as ED_dtHoraFinReal, ED.fPorcentajeRealizado as ED_fPorcentajeRealizado
    10 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED
    11 left join HISTORICOS_AVANZA.HSAE_HIS_HORAPASOPARADA HPP
    12 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
    13 left join AVANZA.SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
    14 where ED.dtJornada = TO_DATE('14/01/2013', 'DD/MM/YYYY') and ED.iIdExpedicion in (-131076)
    15 group by ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal,ED.dtHoraFinReal, ED.fPorcentajeRealizado
    16 having ED.dtHoraInicioReal <> min(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60))
    17 or ED.dtHoraFinReal <> max(dtHora_LlegadaReal)
    18 )
    19 SET ED_dtHoraInicioReal = dtHoraInicioReal,
    20 ED_dtHoraFinReal = dtHoraFinReal,
    21 ED_fPorcentajeRealizado = fPorcentajeRealizado;
    ERROR at line 2:
    ORA-01732: data manipulation operation not legal on this view
    Some help?
    Thanl in advance.
    Edited by: 984483 on 28-ene-2013 1:48

    Thanks for your answer. I tried to rewrite my question.
    SQL> select * from v$version;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
    PL/SQL Release 9.2.0.3.0 - Production
    CORE 9.2.0.3.0 Production
    TNS for 32-bit Windows: Version 9.2.0.3.0 - Production
    NLSRTL Version 9.2.0.3.0 - Production
    I have 2 tables. I like to update one of them (ED_Update) with the data from the another one (ED_Query).
    This example is equivalent:
    create table ED_Query (id number,
         date01 date,
    number01 number)
    insert into ED_Query values (1, to_date('01/01/2013','DD/MM/YYYY'), 10);
    insert into ED_Query values (2, to_date('01/01/2013','DD/MM/YYYY'), 20);
    insert into ED_Query values (3, to_date('01/01/2013','DD/MM/YYYY'), 30);
    insert into ED_Query values (4, to_date('02/01/2013','DD/MM/YYYY'), 40);
    insert into ED_Query values (5, to_date('03/01/2013','DD/MM/YYYY'), 50);
    create table ED_Update (date01 date,
              numberMax number,
              numberSum number)
    insert into ED_Update values (to_date('01/01/2013','DD/MM/YYYY'), 0, 0);
    insert into ED_Update values (to_date('02/01/2013','DD/MM/YYYY'), 0, 0);
    insert into ED_Update values (to_date('03/01/2013','DD/MM/YYYY'), 0, 0);     
    The next update query fails with ORA-00933: SQL command not properly ended.
    update ED_Update
    set ED_Update.date01 = ED_Query.date01,
         ED_Update.numberMax = ED_Query.numberMax,
         ED_Update.numberSum = ED_Query.numberSum
    inner join
         select date01, max (number01) as numberMax, sum(number01) as numberSum
         from ED_Query
         where date01 = TO_DATE('01/01/2013', 'DD/MM/YYYY')
         group by date01
    ) ED_Query
    on ED_Update.date01 = ED_Query.date01
    I think the problem is in the update clause because the next query work:
    select * from
    ED_Update
    inner join
         select date01, max (number01) as numberMax, sum(number01) as numberSum
         from ED_Query
         where date01 = TO_DATE('01/01/2013', 'DD/MM/YYYY')
         group by date01
    ) ED_Query
    on ED_Update.date01 = ED_Query.date01
    Thank in advance.

  • Help with an update with join (works in access)

    This is my working query in ms access...
    UPDATE Caxnode AS A INNER JOIN Caxnode AS B ON A.node_alias = B.node_alias SET A.partition_Type = 'LDOM', A.node_mode = 'LOGICAL', A.host_id = b.host_id, A.num_of_proc = b.num_of_proc WHERE (((A.node_mode)='virtual' Or (A.node_mode)='regular') AND ((B.partition_Type)='LDOM'));
    This doesn't work in oracle, I googled and read that update doesnt work with inner join in oracle..
    can someone please help me translate this query to work on oracle?
    Thanks!
    -nikhil.

    thanks for your reply. however, im a little confused . i want to update the table caxnode for a particular node_alias if the same table has the SAME node_alias defined as partition_Type=ldom
    for eg..
    my table is as follows
    id node_alias host_id node_mode partition_type num_procs
    1 abc abc virtual null 2
    2 abc xyz logical LDOM 4
    3 def def virtual null 2
    4 def ppp logical LDOM 8
    5 abc abc regular null 3
    So those that are ldoms are marked ldom in partition_type, those that are not recognised as ldoms are marked null in partition_type. LDOM's are logical in node_mode, others are either virtual or regular in node_mode.
    Now since there are some old entries that are marked regular/virtual and NULL but are actually LDOMs, I need to go through the table and mark those as LDOM's which have same node_alias marked as LDOM later on.
    In the table above, abc is marked as LDOM in row 2, so row 1 and 5 should reflect that. the host id should change to host_id in row 2 because the same alias is defined as ldom in row 2..
    Same with def.. host_id for def should change to host_id thats in row 4 because def is also defined as ldom in row 4..
    The table should look like this
    id alias host_id node_type num_procs
    1 abc xyz LDOM 4
    2 abc xyz LDOM 4
    3 def ppp LDOM 8
    4 def ppp LDOM 8
    5 abc xyz LDOM 4

  • Update with join/subquery

    I have 2 tables
    tblA(aID, aSeq, aname, aLname)
    tblB(bSeq, bname, bLname)
    I need to update table tblA to set aSeq where the name and Lname match with tblB. Something like
    update zA A
    set A.aSeq =
    select B.bSeq
    from zB B
    where UPPER(B.bname) = UPPER(A.aname)
    and UPPER(B.blname) = UPPER(A.alname)
    What am I doing wrong? Why do I get the error - ORA-01427: single-row subquery returns more than one row

    based on above scenario (tblA => proposal tblB => personnel)
    select rp.prop_id || '| ' || UPPER(rp.prodir_fn) || '| ' || UPPER(rp.prodir_ln)
    from proposal rp
    where exists(
    select p.piid ---------------------------------------------------get matching names from personnel
    from personnel p
    where UPPER(rp.prodir_fn) = UPPER(p.fname)
    and UPPER(rp.prodir_ln) = UPPER(p.lname)
    and EXISTS
    ( select UPPER(q.fname), UPPER(q.lname)     ------------ get matching names of single person that is drop
    from personnel q--------------------------------------------- peron names who have same first and last name different id
    where UPPER(q.fname) = UPPER(p.fname)
    and UPPER(q.lname) = UPPER(p.lname)
    group by UPPER(q.fname), UPPER(q.lname)
    having count(*) = 1
    gives me 3535 matching records
    but
    my update still fails, Please guide
    UPDATE proposal rp
    set rp.pi = (
    select p.piid
    from personnel p
    where UPPER(rp.prodir_fn) = UPPER(p.fname)
    and UPPER(rp.prodir_ln) = UPPER(p.lname)
    and EXISTS
    ( select UPPER(q.fname), UPPER(q.lname)
    from personnel q
    where UPPER(q.fname) = UPPER(p.fname)
    and UPPER(q.lname) = UPPER(p.lname)
    group by UPPER(q.fname), UPPER(q.lname)
    having count(*) = 1
    ;

  • SQL Server updating with join issue

    Could someone explain to me why this update script isn't behaving the way I think it should. I'm currently running the following script:SQLUPDATE [PO_RECVR_HIST]SET [PO_RECVR_HIST].[REF] = ( CASE -- Place MUD or HOCKEY in receiver header reference fields WHEN coalesce([IM_ITEM].[ATTR_COD_1], '') = 'MUD' THEN 'MUD' WHEN coalesce([IM_ITEM].[ATTR_COD_1], '') = 'HOCKEY' THEN 'HOCKEY' ELSE coalesce([PO_RECVR_HIST].[REF], [PO_RECVR_HIST].[REF]) END )FROM [PO_RECVR_HIST] LEFT JOIN[PO_RECVR_HIST_LIN]ON -- Acquire all the line information for each receiver header[PO_RECVR_HIST].[RECVR_NO] = [PO_RECVR_HIST_LIN].[RECVR_NO]LEFT JOIN[IM_ITEM] ON -- Acquire all the item information (specifically attribute code 1) for each line item on the receiver[PO_RECVR_HIST_LIN].[ITEM_NO] = [IM_ITEM].[ITEM_NO]I'm trying to run this script on the PO_RECVR_HIST...
    This topic first appeared in the Spiceworks Community

    1) First Reboot your server and try again for the installation.
    2) If first fail again than Take a backup of Registry first for safe side and then delete the entries of SQL server 2012 if found take a reboot again and try to install again.
    One more thing if installation created any file then move/Delete that also before installation.

  • Update with inner-left-right joins

    On the net I find much confusing information. I am searching for examples about oracle update with joins.
    Someone knows where I can find running examples? (especially Oracle 8i 9i)
    Thanks
    Gaetano Recchi

    867873 wrote:
    On the net I find much confusing information. I am searching for examples about oracle update with joins.
    Someone knows where I can find running examples? (especially Oracle 8i 9i)
    Thanks
    Gaetano RecchiThere are lots of examples on-line if you just search for them. In particular search for a primer on ANSI SQL since "normal" SQL doen't use the inner terminology as much (though outer joins are still talked about).
    Use your favorite search engine and look for ORACLE and ANSI SQL

  • Update with Outer Join

    Is it possible to do an update that involves an outer join on the table being updated?
    Here's what I mean - currently, I have something like:
    UPDATE table_1 t1
    SET col_1 =
    SELECT t2.col_2
    FROM table_2 t2
    WHERE t2.t1_key = t1.t1_key
    WHERE EXISTS
    SELECT t2.*
    FROM table_2 t2
    WHERE t2.t1_key = t1.t1_key
    UPDATE table_1 t1
    SET col_1 = 0
    WHERE NOT EXISTS
    SELECT t2.*
    FROM table_2 t2
    WHERE t2.t1_key = t1.t1_key
    Yes, I could do set all of the table_1.col_1 values = 0 first, and then do the first update, but it is inefficient given the number of records in the table that would be updated twice.
    Is there a way of combining these two updates into a single update statement?

    You could simply use your first update and omit the WHERE EXISTS clause since you want to update all the rows in table_1 anyway.
    If the subquery finds a match, it will update with the selected value. Normally, a non-match would set the column to a null but you can solve that with NVL:
    SQL> select * from table_1;
                  T1_KEY                COL_1
                       1                    1
                       2                    1
                       3                    1
                       4                    1
                       5                    1
                       6                    1
                       7                    1
                       8                    1
                       9                    1
    9 rows selected.
    SQL> select * from table_2;
                  T2_KEY                COL_2
                       1                    9
                       3                    9
                       5                    9
    SQL> UPDATE table_1 t1
      2  SET    col_1 = nvl (
      3                       (SELECT t2.col_2
      4                        FROM   table_2 t2
      5                        WHERE  t2.t2_key = t1.t1_key
      6                       ),0
      7                     )
      8  ;
    9 rows updated.
    SQL> select * from table_1;
                  T1_KEY                COL_1
                       1                    9
                       2                    0
                       3                    9
                       4                    0
                       5                    9
                       6                    0
                       7                    0
                       8                    0
                       9                    0
    9 rows selected.

  • Update with Outer Join, round 2

    Thanks for those of you who helped me out on the first one (I never thought that you could use a one-row SELECT like that).
    However, here is a new version of my problem:
    I have three tables.
    Table_1 has a column that needs to be updated based on values in Table_2 and Table_3.
    Both Table_1 and Table_2 have values used to determine which Table_3 row to use.
    However, not every Table_1 row has a corresponding Table_3 row, in which case the Table_3 value to use is assumed to be 1.
    The tables and corresponding columns are:
    TABLE_1
    value_1 - the value to be updated
    key_2 - a pointer to TABLE_2
    key_3a - a pointer to TABLE_3, or a dummy value if there is no corresponding TABLE_3 record
    TABLE_2
    key_2 - the primary key
    key_3b - a secondary pointer to TABLE_3
    value_2 - a value to be used in calculating TABLE_1.value_1
    TABLE_3
    key_3a - the first part of the unique key
    ley_3b - the second part of the unique key
    value_3 - a value to be used in calculating TABLE_1.value_1
    If there is a row in table_3 that matches the table_1.key_3a and table_2.key_3b values (where table_2.key_2 = table_1.key_2):
    set table_1.value_1 = table_2.value_2 * table_3.value_3
    If there is no such row in table_3:
    set table_1.value_1 = table_2.value_2
    I want to do something like this:
    UPDATE table_1 t1
    SET value_1 =
    SELECT t2.value_2 * NVL(t3.value_3, 1)
    FROM table_2 t2
    LEFT JOIN table_3 t3
    ON (t3.key_3b = t2.key_3b and t3.key_3a = t1.key_3a)
    WHERE t2.key_2 = t1.key_2
    However, Oracle does not allow t1 to be referenced in the ON clause of the outer join.
    (Assume that every key_2 value in table_1 is in table_2 as well - it is only the key_3 value that can be a dummy.)
    If I move "t3.key_3 = t1.key_3" to the WHERE clause, then t1.value_1 is null for rows without the corresponding table_3 value.
    I can do it with a clone of table_1 using ROWIDs:
    UPDATE table_1 t1
    SET value_1 =
    SELECT t2.value_2 * NVL(t3.value_3, 1)
    FROM table_1 t1a
    JOIN table_2 t2
    ON t2.key_2 = t1a.key_2
    LEFT JOIN table_3 t3
    ON (t3.key_3b = t2.key_3b and t3.key_3a = t1a.key_3a)
    WHERE t1a.row_id = t1.row_id
    However, is there an easier way to do this using ANSI joins (i.e. without (+) syntax)?
    I have this feeling I am missing something reasonably obvious here.

    ddelgran wrote:
    Thanks for those of you who helped me out on the first one (I never thought that you could use a one-row SELECT like that).
    I want to do something like this:
    UPDATE table_1 t1
    SET value_1 =
    SELECT t2.value_2 * NVL(t3.value_3, 1)
    FROM table_2 t2
    LEFT JOIN table_3 t3
    ON (t3.key_3b = t2.key_3b and t3.key_3a = t1.key_3a)
    WHERE t2.key_2 = t1.key_2
    However, Oracle does not allow t1 to be referenced in the ON clause of the outer join.
    (Assume that every key_2 value in table_1 is in table_2 as well - it is only the key_3 value that can be a dummy.)
    If I move "t3.key_3 = t1.key_3" to the WHERE clause, then t1.value_1 is null for rows without the corresponding table_3 value.
    I can do it with a clone of table_1 using ROWIDs:
    UPDATE table_1 t1
    SET value_1 =
    SELECT t2.value_2 * NVL(t3.value_3, 1)
    FROM table_1 t1a
    JOIN table_2 t2
    ON t2.key_2 = t1a.key_2
    LEFT JOIN table_3 t3
    ON (t3.key_3b = t2.key_3b and t3.key_3a = t1a.key_3a)
    WHERE t1a.row_id = t1.row_id
    However, is there an easier way to do this using ANSI joins (i.e. without (+) syntax)?
    I have this feeling I am missing something reasonably obvious here.You might want to refer to my post in your original thread how to use join views in updates. You can use ANSI join syntax there, too:
    Re: Update with Outer Join
    You would end up with something like this (note: untested):
    UPDATE
      SELECT t1.value_1, t2.value_2 * NVL(t3.value_3, 1) as new_val
      FROM table_1 t1
      INNER JOIN table_2 t2 ON (t2.key_2 = t1.key_2)
      LEFT JOIN table_3 t3
      ON (t3.key_3b = t2.key_3b and t3.key_3a = t1.key_3a)
    SET value_1 = new_val;And again the same restrictions regarding key-preserved tables apply as described in the post referred to.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Update openquery remote table with join

    Hi All,
    I have a problem with OPENQUERY update on remote table. I've googled for days, and can't solve the problem.
    Here is the problem:
    Local server MS SQL 2005.
    Remote server: MySQL.
    The linked server is communicating through MySQL ODBC 5.1
    I created the following code for update (tried many other version too, this is the last one):
    update openquery(Remoteserver,'select products_id, products_price, products_last_modified, products_stock from products1')
    set
    products_price=A.products_price,
    products_stock=A.products_stock,
    products_last_modified=getdate()
    FROM
    (select * from vi_products_update) AS A INNER JOIN
    openquery(octopus, 'select products_id from products1')AS B
    ON A.products_id=B.products_id
    When I run the query the columns are updated with the same value, for each record. It looks the value is the first which match the criteria. Each (remote and local) table has as primary key products_id. In this example I used as result set for local a view, but I have the same result if I use a table.
    the products_last_modified column is updated in order, and if I update for e.g. the products_price with a constant that is ok too. The problem should be somewhere with join, but I can' get it where.
    THX for any help
    ab

    Hi
    Did you ever solve this problem
    I have the same issue trying to update many rown in a MySQL table from SQL2005 using the syntax below,
    UPDATE
    openquery(DEV,'select id, `desc` from todLocationGroups')
    SET [desc] = V.Destination_Group FROM
    (select * from VTM_TOD_Rate) as V inner join
    openquery(DEV,'select id, `desc` from todLocationGroups') as K
    ON K.id = V.TOD_LG_ID
    but i get this error
    OLE DB provider "MSDASQL" for linked server "KAYOTE_DEV" returned message "Row cannot be located for updating. Some values may have been changed since it was last read.".
    Msg 7343, Level 16, State 4, Line 1
    The OLE DB provider "MSDASQL" for linked server "KAYOTE_DEV" could not UPDATE table "[MSDASQL]". The rowset was using optimistic concurrency and the value of a column has been changed after the containing row was last fetched or resynchronized.

  • Update statement with joining other tables

    Hi ,
    I have two table one is containing xml file , basically i need to read from those xml file then update to another table based on some condition.
    UPDATE TRCB_XBRL_STG_2 STG
    SET PROFIT =
      case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."') is not null
      THEN EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."')
      WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..') IS NOT NULL
      THEN extractValue(XBRL.xbrlfile,'//PROFIT ', 'xmlns:acra=".."')
      ELSE STG.PROFIT
      END,
      SET REVENUE=
      case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..."') is not null
      THEN EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE.', 'xmlns:acra="..."')
      WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..') IS NOT NULL
      THEN extractValue(XBRL.xbrlfile,'//REVENUE', 'xmlns:acra="REVENUE"')
      ELSE STG.REVENUE
      END,
      ... (around 100 columns)
    FROM  TRCB_XBRL xbrl ,TRCB_XBRL_STG_2 STG
    WHERE STG.XBRL_ID = XBRL.XBRL_ID Number of columns are around 100 , please anyone suggest how to use update statement with joining two tables.

    Hi,
    If all the values needed to update a given row of table_x are coming from the same row of table_y (or from the same row of a result set of a query involving any number of tables), then you can do something like this:
    UPDATE  table_x  x
    SET     (col1, col2, col3, ...)
    =     (
             SELECT  NVL (y.col1, x.col1)
             ,         NVL (y.col2, x.col2)
             ,         NVL (y.col3, x.col3)
             FROM    table_y  y
             WHERE   x.pkey   = y.expr
             AND         ...
    WHERE   ...
    ;If the WHERE clause depends on the same row of table_y, then it will probably be simpler and more efficient to use MERGE instead of UPDATE.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Materialized view with join

    In 10g release 2,I tried to create following materialized view with join:
    test_link is a normal table
    test_geom is a table contains a column in SDO_GEOMETRY
    CREATE MATERIALIZED VIEW LOG ON test_link with rowid
    CREATE MATERIALIZED VIEW LOG ON test_geom with rowid,primary key
    CREATE MATERIALIZED VIEW MV_LINK USING INDEX REFRESH FAST ON DEMAND AS
    SELECT li.rowid link_rowid,geom.rowid geom_rowid,li.link_id,geom.link
    FROM test_link li, test_geom geom
    WHERE li.link_id=geom.link_id
    But I always got an error like:
    ORA-12015: cannot create a fast refresh materialized view from a complex query
    If I change the geometry table to another table, everything works fine.
    Anyone have ideas?

    Unfortunately, creating a fast refreshable materialized view on a join with one of the select columns being a user defined type (sdo_geometry is a user defined type) is not allowed. See 5303489 in the metalink bug database.
    You could do like the workaround in the article suggests and create two materialized views and then create a regular view on top.
    In our scenario, our materialized view also contains unions, so we would really like to have one physical object at the end of the day. One approach that we are currently investigating is to create the materialized view (MV1) without the geometry column, which makes it fast refreshable, and also create a materialized view (MV2) on the table containing the geometry column. MV2 is also fast refreshable. We then create a table (T3) that contains all of the columns from MV1, plus a geometry column. An insert, update, delete trigger on MV1 is created. The trigger is used to push all of the columns from MV1 to T3 and the geometry column from MV2 to T3. I have created the above in one of our test environments and haven't encountered any issues yet.
    Let me know if you come up with a better approach.

  • Did I brick my BB Q10? I updated with Sachesi to 10.2.2.932

    Did I brick my BB Q10? I updated with Sachesi to 10.2.2.932. After reboot, I can not make or receive any calls and all I get is: "The 'cellular' phone line is not available. Choose a different phone line and try your call again" "different phone line"? really!? o_O NB! Only software I can use and have is Sachesi because it works with Linux.
    Solved!
    Go to Solution.

     Not knowing exactly what you did with Sachesi as far as also including the radio file...
    I would downgrade back to the last known working 10.2.1 release... 10.2.1.3254 if nothing else.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • How to update with data on two table

    Hi,
    I'm having below problem:
    Table 1: T_UTR(bdate,rec,id,channel,invoice,prod,proc_date)
    Table2: t_upd_utr(bdate,rec,id,channel,invoice,prod)
    I want to update data in t_utr like below:
    update t_utr set proc_date=sysdate,invoice=t_upd_utr.invoice
    where
    t_utr.bdate=t_upd_utr.bdate
    And t_utr.rec=t_upd_utr.rec
    And t_utr.id=t_upd_utr.id
    And t_utr.channel=t_upd_utr.channel
    And t_utr.invoice=t_upd_utr.invoice
    And t_utr.prod=t_upd_utr.prod
    I'm not able to do so with join as join is not possible in update statement.
    Pls advice how can I achieve the above update with least complexity
    Thanks
    Deepak

    update T_UTR
    set proc_date=sysdate,
    invoice=(select t_upd_utr.invoice where t_utr.bdate=t_upd_utr.bdate
    And t_utr.rec=t_upd_utr.rec
    And t_utr.id=t_upd_utr.id
    And t_utr.channel=t_upd_utr.channel
    And t_utr.invoice=t_upd_utr.invoice
    And t_utr.prod=t_upd_utr.prod)
    If you want filter then you can apply filter in where condition in Main update statement.

Maybe you are looking for

  • Is it possible to have multiple "Instances" of iTunes installed/running?

    I have a situation where it would be useful to have multiple iTunes libraries open at the same time. I use Libra 2 to manage my many libraries, but I find it can be a pain to switch back and forth between libraries. Has anyone out there found a way t

  • Personal contacts end up in my Outlook contacts

    Hi all..  Background: - I have access to my work email (Outlook) through my iPhone, including my calendar and contacts.. - In my phone contacts the groups I have are "All contacts", "From my PC (All from my PC)", "Work (All work; Contacts; and Sugges

  • Javascript for cropping PDF

    Hi I know it´s probably quite easy to crop PDF document with jacascript but what I need is that ratio of the result would be 1:1.3 (Widht 1 : Height 1.3). And it should be negative crop (page is not actually cropped at all but enlarged instead of tha

  • Context with counter mapping issue

    I need help with a mapping issue. I have a source document that has multiple line items which in turn contains multiple item texts.  This structure has been simplified below. Source Sample <DOCUMENT> ---<LINEITEM> <ITEMFIELD>itemfield</ITEMFIELD> <IT

  • Asynchronous BPEL callback in version 11.1.1.5.0

    The problem is when i call a composite that has a Asynchronous BPEL the result is included with and error, tried to fix it , google for an answer but no result. i changed JTA transaction from 30 to 3600 seconds but it fixes nothing (the server respon