Update with Select

Hello, I am trying to update all the columns of one table from the records of another table.
I have managed to do a similar thing using the statement below to insert into table 2 all the rows that exist in table 1 and don't exist in table 2.
insert into DFO_FACILIDADE
select IMP.* from DFO_IMPORTADO_OBJECTEL IMP left outer join DFO_FACILIDADE FAC on IMP.FACILIDADE_ID = FAC.FACILIDADE_ID
where FAC.FACILIDADE_ID is null;I've tried the codes below, but none of them worked:
update DFO_FACILIDADE FAC set FAC.* = IMP.*
from DFO_IMPORTADO_OBJECTEL IMP where IMP.FACILIDADE_ID = FAC.FACILIDADE_ID
update DFO_FACILIDADE F (inner join DFO_IMPORTADO_OBJECTEL I on I.FACILIDADE_ID = F.FACILIDADE_ID)
set f.facilidade_identificador = i.facilidade_identificador
update DFO_FACILIDADE set facilidade_identificador = i.facilidade_identificador
from (select f.facilidade_id from dfo_importado_objectel i, DFO_FACILIDADE f where i.facilidade_id = f.facilidade_id) fac_idIs there a way to do this?
Thanks,
Komyg

Try something like:
UPDATE DFO_FACILIDADE FAC
SET FAC.column1 = (SELECT column1
                                FROM DFO_IMPORTADO_OBJECTEL IMP
                                WHERE IMP.FACILIDADE_ID = FAC.FACILIDADE_ID),
       FAC.column2 =  (SELECT column2
                                FROM DFO_IMPORTADO_OBJECTEL IMP
                                WHERE IMP.FACILIDADE_ID = FAC.FACILIDADE_ID)  ;Regards,
Miguel

Similar Messages

  • Update with Select top n statement

    Hi All,
    Can I use update statemet like this..
    Update table1
    set Name=(select top (100) t2.name from table2 t2 where table1.ID=t2.ID)
    Please let me know ASAP its very urgent
    Thanks in Advance
    RH
    sql

    Hi sql9 !
    You might need below query;
    CREATE TABLE Table1 (ID INT,Name VARCHAR(10))
    CREATE TABLE Table2 (ID INT,Name VARCHAR(10))
    --TRUNCATE TABLE Table1
    --TRUNCATE TABLE Table2
    INSERT INTO Table1
    SELECT 1,'ABC' UNION ALL
    SELECT 2,'DEF' UNION ALL
    SELECT 3,'GHI'
    INSERT INTO Table2
    SELECT 1,'JKL' UNION ALL
    SELECT 1,'MNO' UNION ALL
    SELECT 2,'PQR' UNION ALL
    SELECT 2,'STU' UNION ALL
    SELECT 3,'VWX' UNION ALL
    SELECT 3,'YZ'
    UPDATE Table1 SET Name = (SELECT TOP 1 T2.Name FROM Table2 T2 WHERE Table1.ID = T2.ID)
    SELECT * FROM Table1
    --ID Name
    --1 JKL
    --2 PQR
    --3 VWX
    --You can simply re-write your SQL with below query and you don't have to specify TOP Clause inside subquery
    UPDATE T1 SET T1.Name = T2.Name
    FROM Table1 T1
    INNER JOIN Table2 T2 ON T2.ID = T1.ID
    SELECT * FROM Table1
    --ID Name
    --1 JKL
    --2 PQR
    --3 VWX
    Note : In your first query TOP 100 returning more than 1 value from subquery which is not allowed.
    Please let me know if this doesn’t work for you. Hope I have answered you correctly.
    Thanks,
    Hasham

  • Update with Select from a non-existant column

    Hello,
    If I have two tables in Oracle database:
    Table_1 has column id, c1, c2
    Table_2 has column id, c1, c2
    If I run the following select statement, it will give error, because column c3 does not exist:
    select c3 from table_2;
    However, if I run the following update statement, it run successfully with error. It shows, for example, 10 rows updated:
    update table_1 t1 set t1.c2 =
    (select t2.c3 from table_2 t2
    where t2.id = t1.id);
    Could someone explain to me what happens?
    Regards!

    rp0428 wrote:
    >
    It's called a Correlated Sub-Query . It's documented, with examples, in the SQL Language manual
    >
    I'm familiar with correlated sub-queries. That link has NO examples using a column in the FROM list of a sub-query that is NOT in a table in the FROM list of that sub-query.
    You can certainly use constants, or functions in a select list without needing a table reference but I haven't seen any documentation showing an example of selecting a column in a sub-query that doesn't exist in one of the FROM tables.There are no examples of selecting a column from the outer query in a sub-query because in 99.999% of the cases it would be the wrong thing to do, however it is possible. Clearly the sub-query can "see" columns in the outer query otherwise how would it see the values for a correlated sub-query. As Frank said, there is nothing in the documenation that precludes using an outer column in the sub-query, and this paragraph from Frank's link certainly seems to pretty generally refer to the entire sub-query:
    If columns in a subquery have the same name as columns in the containing statement, then you must prefix any reference to the column of the table from the containing statement with the table name or alias. To make your statements easier to read, always qualify the columns in a subquery with the name or alias of the table, view, or materialized view.John

  • JDBC Receiver adapter ( INSERT/UPDATE with SELECT)

    Is it possible to have following kind of SQL Statement comming out JDBC Receiver Adatpter. If yes what would be the corresponding XML Document format for this.
    UPDATE suppliers 
    SET supplier_name = ( SELECT customers.name
    FROM customers
    WHERE customers.customer_id = suppliers.supplier_id)
    This condition also needs to be applied for Insert condition. Any pointer would be useful.
    Thanks,
    Samir

    Hi
    Refer this links,
    http://help.sap.com/saphelp_nw04/helpdata/en/22/b4d13b633f7748b4d34f3191529946/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/b0/676b3c255b1475e10000000a114084/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/2e/96fd3f2d14e869e10000000a155106/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/4d/8c103e05df2e4b95cbcc68fed61705/frameset.htm
    Regards,
    Suryanaryana

  • Ministore not updating with selection

    iTunes 7.4.1 on Intel Mac (mini or macbook). When I have the Ministore on (visible), and I select a song, the minstore display doesn't update. It used to do what is advertised in earlier versions -- showing related songs; but now it doesn't. Anybody seen this or know what's wrong?

    I've just noticed this difference, too. The mini store doesn't update based on my selection in the song listing. I know it won't for items it doesn't recognize, but I'm selecting items I've bought from the store instead of items from CDs, and the mini store is still not updating.

  • Problem with "SELECT...FOR UPDATE OF..." and "POST command" combination

    Problem with "SELECT...FOR UPDATE OF..." and "POST command" combination
    Problem in committing transactions in Multiple Forms (Oracle Forms) with POST built-in command:
    Consider that the following statements are written in WHEN-WINDOW-CLOSED trigger of a called form.
    Statements in called form (Form name: FORM_CHILD):
    go_block('display_block') ;
    do_key('execute_query') ;
    -- Data from table_b will be populated in this block, based on the value of COLUMN_1 obtained
    -- from TABLE_A.
    -- Example: If the value of COLUMN_1 is 10, then all the matching records from TABLE_B, which
    -- are inserted with value 10 in TABLE_B.COLUMN_1 will be fetched and shown here.
    if user_choice = 'YES' then
    commit ;
    else
    rollback ;
    end if ;
    Statements in calling forms:
    There are two calling forms having following statements and it is going to call the above said called form.
    CALLING FORM 1
    Statements in KEY-COMMIT trigger:
    post;
    call_form(form_child, no_activate) ;
    Statements in ON-INSERT trigger:
    select column_1
    from table_a
    for update of column_1
    where column_2 = 'X' ;
    update table_a
    set column_1 = column_1 + 1
    where column_2 = 'X' ;
    insert into table_b ...;
    insert into table_b ...; Statements in KEY-COMMIT trigger:
    post;
    call_form(form_child, no_activate) ;
    CALLING FORM 2:
    Statements in ON-INSERT trigger:
    select column_1
    from table_a
    for update of column_1
    where column_2 = 'X' ;
    update table_a
    set column_1 = column_1 + 1
    where column_2 = 'X' ;
    insert into table_b ...;
    insert into table_b ...;
    insert into table_b ...;
    Our understanding:
    Assume that both the forms are running from two different machines/instances, issuing commit at the same time. In this case, forms will start executing the statements written in ON-INSERT trigger, the moment POST command is executed. Though the commit is issued at the same time, according to oracle, only one of the request will be taken for processing first. Assume that calling form 1 is getting processed first.
    So, it fetches the value available in COLUMN_1 of TABLE_A and locks the row from further select, update, etc. as SELECT...FOR UPDATE command is used (note that NOWAIT is not given, hence the lock will be released only when COMMIT or ROLLBACK happens) and proceed executing further INSERT statements. Because of the lock provided by the SELECT...FOR UPDATE command, the statements in calling form 2 will wait for the resource.
    After executing the INSERT statements, the FORM_CHILD is called. The rows inserted in to TABLE_A will be queried and shown. The database changes will be committed when user closes the window (as COMMIT is issued in its WHEN-WINDOW-CLOSED trigger). Then the SELECT...FOR UPDATE lock will be released and calling form 2's statements will be executed.
    Actual happenings or Mis-behavior:
    Calling form 2 starts executing INSERT statements instead of waiting for SELECT...FOR UPDATE lock. Also, the value selected from TABLE_A.COLUMN_1 is same in both the calling forms, which is wrong.
    The rows inserted into TABLE_B are having similar COLUMN_1 values in calling form 2 and they are fetched and shown in the called form FORM_CHILD.
    Note that in calling form 2 also POST only is issued, but the changes posted there are accessible in calling form 1 also, which is wrong.
    Kindly suggest us as to how to fix above problem. It will be much use, if you can send us the information regarding the behavior of Oracle Forms POST built-in also.
    Our mail ID: [email protected]
    Thanks a lot in advance.

    You have several problems:
    1. On-Insert will ONLY run if you have created a new record in a base-table block. If you haven't done that, then the POST command will not cause it to run.
    2. Select for update without a "no wait" will lock records for the first form, but when the second form tries this, it will hit the ORA-00054 exception, and will NOT wait. The only way you could make it wait is to issue an UPDATE sql command, which is not such a good way to go.
    All POST does is issues SQL insert or update commands for any changes the user has made to records in a form's base-table blocks, without following with a Commit command.
    Also understand that Commit is the same as Commit_Form, and Rollback is the same as Clear_Form. You should read up on these in the Forms help topics.

  • IPhone 4s updated with IOS 8. Not the calendar will not show a full list of dates. Instead it shows the whole month with the list of the day selected. I want to have my full list back. So much easier to scroll thru when making appointments.

    iPhone 4s just updated with IOS 8. Now my calendar does not offer the full list of items by day on the screen. Instead I see the month and below the month are the appointments in a list for the selected day only. I would like the option to have the full list available as it is much easier to scroll thru the list when making appointments.

    Hello memormor,
    Thank you for visiting Apple Support Communities.
    To see the full scrollable list of events, start from the day view (tap on a day), not the month view, then click .
    Calendar at a glance - iPhone
    View a list of events. In month view, tap to see a day’s events. In day view, tap .
    Take care,
    Nubz

  • SELECT FOR UPDATE with the SKIP LOCK clause

    Hi,
    I have a query regarding the SELECT FOR UPDATE with the SKIP LOCK clause.
    Whether this will be really good for parallel processing.
    Also if we are selecting a set of records in a cursor whether the lock will be done at the records level once we fetch the records?
    Also do we have any known issues with this one?
    We are trying to figure out whether this will fit for business requirement, we are trying to do a implement a threading kind of thing for our stored procedure invocation in background using shell script.
    Any suggestion or feedback on this will be helpful for us.
    Thanks a lot for the support given....
    Regards,
    Basil Abraham.

    http://www.oracle.com/technology/oramag/oracle/08-mar/o28plsql.html
    Please read the above thread for few information...Thanks!

  • Trigger with SELECT-FOR-UPDATE

    There is a trigger on a table, which updates a particular column with SYSDATE BEFORE an INSERT OR UPDATE in the table.
    CREATE OR REPLACE TRIGGER my_schema.trg_Order
    BEFORE INSERT OR UPDATE
    ON my_schema.ORDER
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    :NEW.LAST_UPDATE_DATE := SYSDATE;
    END;
    If I update the record using PL/SQL with SELECT-FOR-UPDATE & then UPDATE, the column LAST_UPDATE_DATE is not updated with the SYSDATE.
    But if it is done by using the UPDATE Statement, then the column LAST_UPDATE_DATE is correctly updated with the SYSDATE.
    Why? How can I ensure that for SELECT-FOR-UPDATE & then UPDATE will also update the LAST_UPDATE_DATE with SYSDATE.

    The Table Order has a BLOB column.

  • Can NOT update video automatically with selected playlists!

    I just bought my iPod today and when I try to put some video on it, the movie does not appear anywhere.
    when I click on the Video button, the "automatically with selected playlist" option is hidden and I cant click on it, and no video title can be observed.
    Do you have to put video in to certain folder to add them?
    And how come the Automatlcally with selected playlist is hidden?

    I had the same issue, however I used this program;
    http://www.videora.com/en-us/Converter/iPod/
    I'm pasting this from the Videora site, the settings worked for me when others didn't, enjoy:
    Configuring videora converter
    0) Start Videora iPod converter.
    1) Click setup in the left nav.
    1.5) Click the profiles tab.
    2) Click new profile.
    3) Now, configure that profile:
    profile name: ipod
    in the video settings section...
    mode: MPEG-4 > CBR
    resolution: 320x240
    passes: one
    bitrate: 768 kbps (384 kbps also works)
    framerate: 29.97 fps
    in the audio settings section...
    bitrate: 128 kbps
    sample rate: Input
    channels: stereo
    4) Click apply to save the profile.
    Now, you're ready to transcode.
    1) Click convert on the left nav.
    2) Click the transcode new video button.
    3) Pick your source video. Mine was an AVI from a torrent.
    4) Under quality profile, choose "ipod", the profile you created using the steps above.
    5) Click start.
    Now you're ready to get the video on your ipod
    1) In iTunes, under the File menu, select add file to library. Find the transcoded one. By default, the transcoded videos pop out under the Videora install directory.
    2) Drag and drop to your ipod.
    Questions/observations:
    1) I haven't been able to get H264 anything to work. Is it broken? How much smaller than MPEG4 is it?
    2) 768 kbps video was about 400 megs/hour; 384 kbps video was about 231 megs/hour. I could readily see a difference in video quality.

  • Problems with software the update with Nokia 6233

    Problems with software the update with Nokia 6233
    Hello,
    I have so far some-paints tries my software to update.
    Each time the update procedure begins, sometime stands then on the telephone “test mode”.
    On the computer wars I the reference in the update manager “connection to the telephone broken off” and wants the update to again start.
    If I change my profile attitudes since that for example, then after a telephone restart again deleted.
    What there can I make?
    GreetingsMessage Edited by adisaily on 24-Aug-2007 09:03 AM

    It sounds like your 5800 has the earpiece fault that was common with 5800's made before February.
    You need to take it to a nokia care point for repair under warranty.
    Care points/service centres and repair info:
    UK • Europe • Asia-Pacific • USA •
    Canada • Middle East and Africa
    Elsewhere: Click here, select your country, go to the support section, then select repair.

  • I have a column where I have implemented writeback, its working fine. On top of this I need to show 0 as No and 1 as yes in our report, that is also done. Now I want to enter Yes in a column where it was no and I want database table to get update with 1.

    I have a column where I have implemented writeback, its working fine. On top of this I need to show 0 as No and 1 as yes in our report, that is also done. Now I want to enter Yes in a column where it was no and I want database table to get update with 1. I am not sure how to do it. SOmeone please help me out.

    Hi ,
    In your write back XML  try the below  query insert
    INSERT INTO TABLE_XYZ (attribute1)  values (SELECT CASE  WHEN @{C1}=’Yes’ then 1 when @{C1}=’No’ then 0 else null end from dual)
    Regards
    Rajagopal

  • Gr Ir Assignment Updation with PO and Line Item

    In the GL for GR IR Account the sort key was not  maintained with PO number due to which the assigment field in the line item was getting updated with the posting date and not with the PO & LIne Item details.
    We have made the requiste changes and new items are getting updated properly.
    But require assitance in updating the earlier line items.
    As of date total line items are more than  0.15 mn.
    Please suggest some method to automatically update the assigment field of the GR IR Line items with the PO Details.
    Regards
    Mukesh

    Hi,
    You can use a substitution to update the field through FI. Use GGB4 for wirting a substitution you may need some ABAP coding to substitute PO no and line items in the assignment field.  rule would be Co code =XXX and GL account =xxx and Posting date earlier than =xxxx  then concatenrate EBELN and EBELP in Assigment field Zounr.
    Then execute FBL3N and edit the assignment field by selecting all the documents and then save it you should see the PO line items populated. You can leave the substitution on or you can remove it after updating,
    Regards
    K.R

  • Mass Updating of Selected Rows

    (As you can see from my low number of posts I'm new to ApEx, so any information you can provide is appreciated.)
    Hi,
    I've been asked to include what I consider a heavy duty feature on a report. It has been requested that there is a form region above a report region. The form will have some fields on it to be used to mass update selected rows.
    For instance, let's say the report is a list of employees and their dept and the form has a dropdown dept field that contains a list of depts. They want to be able to select certain employees on the report, then select a dept from the form and then click an Update Rows button. They want the selected rows to be updated with the selected dept. * Also, they don't want the report to be editable. * The only way to update any rows is thru the Update Row button.
    I'm new to ApEx and can code in JavaScript, but am not an expert in either. And, I'm still trying to figure out what JavaScript syntax works in Element Attributes, etc. fields. But, I digress.
    I have looked over several threads, and went to several demo pages, and have learned some things. Hopefully they are correct. If not, please correct me.
    - Using the Row Selector is tricky.
    - You can get the Row Selector on a regular SQL report by changing it to Updateable SQL, adding the Row Selector type, and changing it back.
    - You can only see row information on a column if the column is editable.
    I now have a report that is NOT editable and has NO editable columns. And the report has the Row Selector. Also, the ID (key) of each row is the first column of each row. (It's a link field that populates another page.) With the ID I can populate the correct record. I'm thinking I need to populate the ID again in another column into a text field and then be able to access that value on the selected rows.
    Here's my dilemma. (That is, if I'm on the right track.) I need to know which rows are selected and then access the ID (key value) of that row. After that I can let my PL/SQL do the work.
    - - 1. How does the 2nd ID need to be defined such that people can't edit it, but the value can be retrieved? And, how is this done? I assume something can be put in the Element Attributes. If so, will you please provide the code?
    - - 2. What is the trick to knowing which rows are selected? An example snippet of code would be great here too.
    - - 3. Also, tell me if I'm on the wrong track and need to provide a solution in a different way.
    Sorry for the novel, but I wanted you to have a good idea of what I'm trying to accomplish so you may provide appropriate answers.
    Thanks much, Tony

    Hi Tony,
    check out the following threads:
    Re: Reference a value within a report????
    Re: MRU - trying to restrict UPDATE to only certain users - everyone INSERT
    BTW, you don't have to use any JavaScript. When you write your "Update pl/sql process" for the tabular form, just reference you page item which contains the department for your mass update.
    eg.
    FOR ii IN 1 .. Apex_Application.g_f01.COUNT
    LOOP
        UPDATE EMPLOYEES
          SET DEPARTMENT_ID = :P4_NEW_DEPARTMENT_ID
        WHERE EMPLOYEE_ID   = Apex_Application.g_f02(Apex_Application.g_f01(ii))
    END LOOP;Hope that gives you a direction how to solve that
    Patrick
    Check out my APEX-blog: http://inside-apex.blogspot.com
    Check out the ApexLib Framework: http://apexlib.sourceforge.net

  • Installation Failure: Windows failed to install the following update with error 0x800F0922

    Hi folks,
    I have a HP Elitebook Folio 9470p.  It came with Windows 8, and I installed it on my corporate domain.  I was trying to do some Windows updates so  I could upgrade it to Windows 8.1, but it fails installing the updates, whether or not I try
    to install them one at a time or all of them.  It has about 18 updates it needs from security updates to a .net framework update.  I run Symantec EP, and disabled it, checked for driver updates for things like display and networking and they are
    all up to date.
    I'm at a loss as to what to do.  It gives this error in the event log for each file, Event ID 20.
    Installation Failure: Windows failed to install the following update with error 0x800F0922: Security Update for Windows 8 for x64-based Systems (KB2862152).
    This is the example for KB2862152, but it gives the same error for every one.  I've tried to auto fix for Windows update issues and it fixed a couple of the issues, but not all of them, and provides no other help.
    I also deleted folders and files from the SoftwareDistribution folder as well, to no avail.  Any ideas what I can do to get whatever updates it needs, so I can fully patch it, and upgrade it to Win 8.1?
    Thanks for any help!

    Hi MM. Mr Kywildcat and Vegan Fan,
    GOOD NEW ! At this time, my issue is solved. The only black side is "how ?" : I hope that we will get a response some day ; however, and for in information  pnly - hoping this could help someone - I resume some actions which allowed this the happy end
    1) about installing 8.1 : I wanted to be sure that gain/pain ratio was positive, and that upgrading from a (potentially) damaged system would'nt produce something looking like a new Win 8.1, but difficult to maintain and keeping some negative potentialities.
    2) I was influenced by the fact that this
    0x800F0922  error acted as "a serial killerror", whose root cause could be a unique update error at reboot time concerning several (>20) packages, so I decided to test some manual upgrades.
    3)   Manual update (i.e. manual download and maunching of .msu packages) of the 2 following packages
    (whose update previously failed on a Windows Update) was successful : .NET Framework version 3.5 for  x64 (KB2898866) and Camera Codec Pack Windows 8 for x64 (KB2899190)
    4) So I decided to try Windows Update on a selection of packages, first : those concerning .Net Framework 3.5 and 4.5 (that is: KB2898866, 2901120, 2898865) --> Successful !
    5) finally, I selected almost all other packages, with some exceptions wich I (think to) have no need for : KB2871690, 2904659, 2843630. To be complete, here is the list of pakages updated one time at all :
    KB 2892074, 2893294, 2893984, 2909210, 2912390, 2916036, 2889784,2903938, 2911101, 2913152, 2917499
    --> always succesful.
    I am not a specialist, but I uess that this 0x800F0922 error hides another problem which is globally "H-RESULTED"
    to all updates pending in one update operation with reboot. This could be assumed from this CBS.log exterped from my last wrong attempts, where root cause seems not to be
    0x800f0922, but 0x80004003 :
    2014-02-15 21:29:13, Info                  CBS    Could not get active session for current session file logging [HRESULT = 0x80004003 - E_POINTER]
    2014-02-15 21:29:13, Info                  CBS    Not able to add pending.xml.bad to Windows Error Report. [HRESULT = 0x80070002 - ERROR_FILE_NOT_FOUND]
    2014-02-15 21:29:18, Error  CBS    Startup: Failed to process advanced operation queue, startupPhase: 0.  A rollback transaction will be created. [HRESULT = 0x800f0922 - CBS_E_INSTALLERS_FAILED]
    Anyway, thanks to you who spent some of your time to describe issues and search/ suggest solutions ; I will upgrade my system to 8.1 anyway, some of this day, when I am sure that my configuration does not hides some other problem. I thing that potential
    issue remains until maybe a new KB corrects it, wrong :-) ?
    And I hope that you - Mr Kywildcat - can upgrade your system on "current levels" trying similar attempts. 
    Phil   

Maybe you are looking for