How does this UPDATE update multiple rows?

For the UPDATE in the following script, what values are selected to update Table2? For example, for a row in Table2 (ie. 'NY') there are several rows in Table1 that can be used for the update.
Thanks.
create table Table1
Col1 varchar(10),
Col2 varchar(10),
Col3 varchar(10)
Insert into Table1
select 'FL', 2, 2
union
select 'FL', 2, 2
union
select 'FL', 2, 5
union
select 'FL', 2, 3
union
select 'NY', 2, 2
union
select 'NY', 1, 3
union
select 'NY', 2, 2
union
select 'NY', 2, 3
union
select 'CA', 3, 2
union
select 'CA', 5, 1
union
select 'CA', 4, 2
union
select 'CA', 2, 3
create table Table2
Col1 varchar(10),
Col2 varchar(10),
Col3 varchar(10),
Ignore varchar(10)
Insert into Table2 (Col1, Ignore)
select 'FL', 1
union
select 'FL', 2
union
select 'FL', 3
union
select 'FL', 4
union
select 'NY', 5
union
select 'NY', 6
union
select 'NY', 7
union
select 'NY', 8
union
select 'CA', 9
union
select 'CA', 10
union
select 'CA', 11
union
select 'CA', 12
update T2
set Col2 = T1.Col2,
Col3 = T1.Col3
from Table1 T1 inner join Table2 T2
on T1.Col1 = T2.Col1
select col1, col2, col3 from Table1
select col1, col2, col3 from table2
VM

When you use Merge syntax, it will not run. You can check the error message:
create table Table1
Col1 varchar(10),
Col2 varchar(10),
Col3 varchar(10)
Insert into Table1
select 'FL', 2, 2
union
select 'FL', 2, 2
union
select 'FL', 2, 5
union
select 'FL', 2, 3
union
select 'NY', 2, 2
union
select 'NY', 1, 3
union
select 'NY', 2, 2
union
select 'NY', 2, 3
union
select 'CA', 3, 2
union
select 'CA', 5, 1
union
select 'CA', 4, 2
union
select 'CA', 2, 3
create table Table2
Col1 varchar(10),
Col2 varchar(10),
Col3 varchar(10),
Ignore varchar(10)
Insert into Table2 (Col1, Ignore)
select 'FL', 1
union
select 'FL', 2
union
select 'FL', 3
union
select 'FL', 4
union
select 'NY', 5
union
select 'NY', 6
union
select 'NY', 7
union
select 'NY', 8
union
select 'CA', 9
union
select 'CA', 10
union
select 'CA', 11
union
select 'CA', 12
Merge Table2 T2
Using Table1 T1
on T1.Col1 = T2.Col1
When Matched Then
UPDATE
set Col2 = T1.Col2,
Col3 = T1.Col3;
Msg 8672, Level 16, State 1, Line 64
The MERGE statement attempted to UPDATE or DELETE the same row more than once. This happens when a target row
matches more than one source row. A MERGE statement cannot UPDATE/DELETE the same row of the target
table multiple times. Refine the ON clause to ensure a target row matches at most
one source row, or use the GROUP BY clause to group the source rows.
--select col1, col2, col3 from Table1
--select col1, col2, col3 from table2
--drop table table1
--drop table table2

Similar Messages

  • How does this work with multiple systems backing up with time machine

    I was wondering as Apple states that this will do multiple time machine backups as in multiple computers, how does this do this? I am assumng that it will require me to partition the srive in the unit as multiple partitions. 1 for each time computer with time machine running.

    I'm sorry, I'm not quite sure how to interpret your answer so I'll ask for clarification.
    Do you mean that the backup belonging to each user will be protected by filesystem perms? In other words Alice's backup will be owned by Alice and only readable by her, ditto for the hyperthetical Bill?
    I guess in other words, does Time Machine preserve file ownership perms?

  • How can I update multiple rows?

    Hi all,
    How can I realize an Update on multiple rows? An Update statement would look like this
    UPDATE table SET value = oldvalue + x WHERE condition_field > y;My problem is: How can I execute such a statement with BC4J? I don't linke to step through the complete result set row by row.
    Thanks,
    Axel

    Get your application module object and issue this statement:
    am.getTransaction().executeCommand(<string>);This should be what you're looking for.

  • How can I update multiple rows based on comparison of fields table1 and 2

    I create the following SQL to test what I thought was a method to update those records where the fields below match, but what ends up happening is that the update functions works the first time, and then basically updates everything to null. I am not understanding what I am doing wrong. New at this.
    UPDATE SLS_HDR B
    SET ( B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
    B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
    B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
    B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT )
    = (SELECT
    A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
    A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
    A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
    A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE
    FROM
    SLS_HDR_TEMP A
    WHERE
    A.FIN_COMP = B.FIN_COMP AND
    A.LOG_COMP = B.LOG_COMP AND
    A.ORD_NO = B.ORD_NO AND
    A.TRANS_DT = B.TRANS_DT AND
    A.BP_TYPE = B.BP_TYPE AND
    A.STATUS <> B.STATUS);
    Can anyone advise?
    Thank you,
    Edited by: 903292 on Dec 19, 2011 1:15 PM

    you donot have where clause in your update so un-matched rows will be updated with null values
    UPDATE SLS_HDR B
    SET ( B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
    B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
    B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
    B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT )
    = (
              SELECT
              A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
              A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
              A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
              A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE
              FROM
              SLS_HDR_TEMP A
              WHERE
              A.FIN_COMP = B.FIN_COMP AND
              A.LOG_COMP = B.LOG_COMP AND
              A.ORD_NO = B.ORD_NO AND
              A.TRANS_DT = B.TRANS_DT AND
              A.BP_TYPE = B.BP_TYPE AND
              A.STATUS= B.STATUS
    WHERE EXISTS
         select null from SLS_HDR_TEMP A
         WHERE
         A.FIN_COMP = B.FIN_COMP AND
         A.LOG_COMP = B.LOG_COMP AND
         A.ORD_NO = B.ORD_NO AND
         A.TRANS_DT = B.TRANS_DT AND
         A.BP_TYPE = B.BP_TYPE AND
         A.STATUS= B.STATUS
    )OR using Merge
    Merge into SLS_HDR B
    using SLS_HDR_TEMP A
    on (A.FIN_COMP = B.FIN_COMP AND
    A.LOG_COMP = B.LOG_COMP AND
    A.ORD_NO = B.ORD_NO AND
    A.TRANS_DT = B.TRANS_DT AND
    A.BP_TYPE = B.BP_TYPE AND
    A.STATUS= B.STATUS)
    when matched then update set (B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
    B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
    B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
    B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT ) = (A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
    A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
    A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
    A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE)HTH...
    Thanks

  • How can I update multiple rows in table using a single form button and checkboxes

    I have a project where the visitors can select multiple productos and once the click on the PURCHAS button it updates the selected records.

    You have not mentioned the programming language that you are using, but here's a link that could help you if you are using ASP.
    http://csharpdotnetfreak.blogspot.com/2009/05/edit-multiple-records-gridview-checkbox.html
    Also, have a look at this discussion thread
    http://forums.asp.net/t/1470882.aspx

  • How can i update multiple row in a advance table

    Dear all,
    hope you are well enough.
    suppose i have a table in a OA page where there are several transactions.
    i would like to add a check box in front of every row.
    when i check the transactions(rows of OA pages) and submit then one column of a table will be updated in database.
    how can i implement that.
    Please explain
    Regards,
    Mofizur

    Hi,
    Refer below code for iteration:
    OAViewObject appVO = (OAViewObject)am.findViewObject("ApprovalsWVO1");
    OARow row = (OARow)appVO.first();
    for(int i=0;i<appVO.getRowCount();i++)
    String appStatus=appVO.getCurrentRow().getAttribute("ApprovalStatus").toString();
    if(appStatus.equalsIgnoreCase("NEW"))
    newRow.setAttribute("appTrans",Boolean.FALSE);
    else
    newRow.setAttribute("appTrans",Boolean.TRUE);
    System.out.println(appStatus);
    row = (OARow)appVO.next();
    Regards
    Meher Irk

  • Update multiple rows based on two columns in same row

    I have a 1000 rows in a table I would like to update with a unique value. This unique value is a cocatenation of two columns in teh same row.
    Each row has a (i) date and a (ii) time and a (iii) date_time column. I would like to update the date_time (iii) column with a cocatenation of the (i) date and (ii) time columns.
    I know how I would update a single row but how can I update multiple rows with a cocatenation of each of the two columns - i.e put a different value into the date_time column for each row?

    this?
    update table tab_name
    set date_time =date||time
    where your_condition

  • Updating multiple rows in a table in ADF

    Hi
    How do we update multiple rows in a table.
    Onclicking a update button the changed rows must be updated.

    Hi Prince,
    currently I am selecting one row from the table and rendering a region at the top of the table and capturing the user entered data with the following code:
    ViewObjectVOImpl vo = getViewObjectVO1();
    Row CurrentRow = vo.getCurrentRow();
    //After this I perform the checks like user entered value is not null or check input as per business logic.
    if(CurrentRow.getAttribute("attributeName") ==null){
    //Add what message you want to display
    //Add other business logic.
    After making all the checks, i commit it.
    getOADBTransaction().commit();
    Now in my new page I am capturing the user input in the table itself like an excel sheet. Suppose there are ten rows in my advanced table on my page, and each row has one editable field. I have one save button at the bottom of the table.
    Now on clicking the save button I have to capture the user input, check whether there is any null value and if all the entered data is correct then only I should commit it.
    Can you please let me know how we can accomplish that.
    Regards
    Hawker

  • Update multiple rows involving spatial data

    Hi,
    i have 2 table, that are
    temp
    store_id
    store_state
    geom mdsys.sdo_geometry
    us_states
    state
    geom mdsys.sdo_geometry
    i have indexed both table with spatial index.
    If i wanna find state that temp.geom is inside us_states.geom using
    SQL> select state from us_states, temp
    where sdo_inside(temp.geom, us_states.geom) = 'TRUE';
    it's work
    but if i wanna update temp.store_state using
    SQL> update temp set store_state = (select state from us_states
    where sdo_inside(temp.geom, us_states.geom) = 'TRUE');
    it gives this error
    update temp set store_state = (select state from us_states where sdo_inside(temp.geom, us_states.geom) = 'TRUE')
    ERROR at line 1:
    ORA-13226: interface not supported without a spatial index
    ORA-06512: at "MDSYS.MD", line 1723
    ORA-06512: at "MDSYS.MDERR", line 8
    ORA-06512: at "MDSYS.SDO_3GL", line 62
    ORA-06512: at "MDSYS.SDO_3GL", line 192
    any idea how can i update multiple rows that involving spatial data?
    Thanks
    Hadi

    Hadi,
    There are a number of things wrong with the second item. First up you most likely will return more than one row, which is not allowed as the = expects only one item.
    Here is what I would use, which will update everything that meets the requirements, and ignore the rest:
    UPDATE (
    SELECT /*+ bypass_ujvc */
    state, store_id, store_state
    FROM temp, us_states
    WHERE sdo_inside(temp.geom, us_states.geom) = 'TRUE')
    SET store_state = state;
    With the /*+ bypass_ujvc */ you're telling the db to not worry about requiring a "unique join view condition" -- which roughly mean "trust me, my rows are key preserved." This is important since there is really no "hard" key-based relationship to tie the two together.
    However, unless you really think there are stores that border on two states, this will run much quicker with an anyinteract comparison.
    Bryan

  • BC4J datagrid to update multiple rows

    Hi,
    How do we update multiple rows at a time in a BC4J JSP with Struts. I intend to have a datagrid control on a JSP so that users may update multiple rows at a time and click 'Update' once.
    There is a possible (workaround) solution using struts nested tags but one would lose the benefits of JBO tags on using struts tags (e.g Calendar control would not be visible for Date input).
    Any implementation suggestions?
    Regards,
    Ashish

    Does the database only contain data where there are events on a given 15-minute time slot?

  • How to update multiple rows in one query using php

    i am new to this can any one help me how to update multiple rows at a time i am doing an school attendance page

    Often the situation is such that you have multiple courses across a range of dates.So students may take more than one course, and you need to track attendance for each course date. The following graphic demonstrates this:
    In such a situation, you need four database tables as follows:
    students (student_id, student_name, etc.)
    courses (course_id, course_name, etc.)
    students_courses (student_id, course_id)
    attendance (student_id, course_id, dater)
    A fifth table may also be needed to define the dates of courses, but you may also be able to build this array programmatically by using PHP's robust date functions, which can give you, for instance, all the Tuesdays and Thursdays between a start date and end date.
    The students_courses table simply keeps track of which students are taking which courses, so it has just two columns for the primary keys of both of the main tables. The attendance table is similar, but it also includes a date field. The following view of the attendance table demonstrates this:
    So if David's solution does cover your needs, consider yourself lucky, because this could quickly grow from a beginner-appropriate project to a moderately advanced one.

  • HT2357 So how does this work on Mountain Lion? I cannot seem to ignore the iTunes 11 updates, which now seem to appear every 5 minutes!!

    So how does this work on Mountain Lion? I cannot seem to ignore the iTunes 11 updates, which now seem to appear every 5 minutes!!

    Fantastic!  Didn't work at first so restarted App store and tried again.  This time it asked 'ignore update'.  All gone!

  • How does one update Flash? I currently cannot watch videos on You Tube, it says I need to upgrade, I have no problem doing this on a PC.

    How does one update Flash? I currently cannot watch videos on You Tube, it says I need to upgrade, I have no problem doing this on a PC.

    If you're not using chrome you can just go to adobe's website (http://get.adobe.com/flashplayer/) and download the newest flash player.  You run the .dmg and then open the application, which updates flash.  With the latest version of flash there should be a preference pane within system preferences to allow you to change settings and check for updates.

  • Update Multiple Rows using Row Selector

    Hi,
    I want to update multiple rows using a tabular form with row selector, and an item in another region of the page, using an update expression and a button.
    The syntax would be like this:
    update MY_TABLE set UPDATABLE_COLUMN = :P10_NEW_VALUE where {row selector = true}
    What is the syntax for the WHERE clause, anyone knows? In the manual there is no information at all for doing this.
    PD. I added the row selector after creating the form, so I don't have any wizard-created MRU processes in the page.
    HTMLDB version is 1.6
    Thanks.

    Hi,
    I want to update multiple rows using a tabular form with row selector, and an item in another region of the page, using an update expression and a button.
    The syntax would be like this:
    update MY_TABLE set UPDATABLE_COLUMN = :P10_NEW_VALUE where {row selector = true}
    What is the syntax for the WHERE clause, anyone knows? In the manual there is no information at all for doing this.
    PD. I added the row selector after creating the form, so I don't have any wizard-created MRU processes in the page.
    HTMLDB version is 1.6
    Thanks.

  • Updating multiple rows

    Hi,
    I have a problem updating multiple rows.
    I have the following update:
    update POI.PERFTABLE p set P.PERF_3YEAR_ANNO =
    (Select
    PERF_ANNO_DAUER
    rtrim(fs.match),
    3
    From POI.FONDSSTAMM fs ) where p.MATCH=match
    but I become the error: ORA-01427: single-row subquery returns more than one row.
    How must I write my SQL-Command that it works??????????
    thanxx
    Schoeib

    Hhhhmmmmm,
    -- So - this doesn't work .......
    UPDATE  POI.PERFTABLE p
    SET     P.PERF_3YEAR_ANNO =
        (   SELECT  PERF_ANNO_DAUER ( RTRIM( FS.Match ), 3 )
            FROM    POI.FONDSSTAMM fs
    WHERE   P.Match = v_Match
    -- Maybe - you could force the sub-select to return a single row.
    UPDATE  POI.PERFTABLE p
    SET     P.PERF_3YEAR_ANNO =
        (   SELECT  PERF_ANNO_DAUER ( RTRIM( FS.Match ), 3 )
            FROM    POI.FONDSSTAMM fs
            -- Restrict the sub-query to returning a single row.
            WHERE   FS.Some_ID = P.some_Id
    WHERE   P.Match = v_Match
    or even
    -- Since you are using a function why not adjust the function,
    --  or write a simular one, so that something like this would work.
    UPDATE  POI.PERFTABLE p
    SET     P.PERF_3YEAR_ANNO = PERF_ANNO_DAUER ( RTRIM( P.Match ), 3 )
    WHERE   P.Match = v_Match
    ;Dude,
    Eric Kamradt

Maybe you are looking for

  • Indesign transparency multiply pdf/x-1a pdf/x-4 export pdf object not visible

    Hello, I've created a simple Indesign cs4 document under osx demonstrating the problem. I've copied from an Indesign document a rectangle with a fill color 100% cyan and a transparency effect multiply and paste the object within a new created documen

  • HD feed into OnLocation CS3 or CS4

    Does anyone have any recommendation for a conversion tool to receive HD from a camera and pass into OnLocation through firewire? (My small camera only has an HDMI and an analog output, no firewire. I can convert the analog but prefer a digital signal

  • How do I uninstall Quicktime 7?

    Wow, Quicktime 7 is terrible, and it unregistered my QT6 Pro key. How do I uninstall Quicktime 7 and go back to QT6?

  • Hi, I am using the photshopcc trial and will be continuing with the full cc if I can solve an issue I have.

    Every time I start PS I get several quick command screen flash on and off (dos boxes). One of those boxes stays on (eok_lvalue_adjust) and I get the message clc.exe has stopped working. This happens again a few seconds later with the same message. If

  • Security Manager Error

    Hi! I'm using a security manager in an application. After I install the security manager it is not able to open a server socket. I'm including the code here. What am I doing wrong??? Its a very simple Seccurity manager where I'm just preventing read/