Need to update column in table from joining the two tables

Hi
i want to update a table by joining two table but i m getting the below error
single row subquery returns more than one value.
i m using following query
update table2
set deposite_date=(select a.deposit_date from table1 a,table2 b
where a.ban=b.ban and (a.deposit_date between b.cy_start_date and b.due_date))
table2
ban due_date cy_start_date deposite_date
100 5/6/2011 22/05/2011
101 7/11/2011 22/05/2011
102 5/25/2011 22/05/2011
table1
ban      deposit_date
100      04/12/2011
100      04/15/2011
102      03/25/2011
101      04/26/2011
101      05/06/2011
101      07/26/2011
can i insert latest deposit_date from table1 which lies between b.cy_start_date and b.due_date
Thanks

Hi,
Welcome to the forum!
876466 wrote:
Hi
i want to update a table by joining two table but i m getting the below error
single row subquery returns more than one value.Exactly!
(   SELECT  a.deposit_date
    FROM    ...returns all deposit_dates.
(   SELECT  MAX (a.deposit_date)
    FROM    ...would return only the latest one.
Also, you need to correlate the sub-query to the main query, so that it only looks for rows with the same ban.
i m using following query
update table2
set deposite_date=(select a.deposit_date from table1 a,table2 b
where a.ban=b.ban and (a.deposit_date between b.cy_start_date and b.due_date))
table2
ban due_date cy_start_date deposite_date
100 5/6/2011 22/05/2011
101 7/11/2011 22/05/2011
102 5/25/2011 22/05/2011
table1
ban      deposit_date
100      04/12/2011
100      04/15/2011
102      03/25/2011
101      04/26/2011
101      05/06/2011
101      07/26/2011
can i insert latest deposit_date from table1 which lies between b.cy_start_date and b.due_datePerhaps you need something like this:
UPDATE  table2     b
SET     deposit_date     =
         (    SELECT  MAX (a.deposit_date)
               FROM      table1           a
           WHERE      a.ban          = b.ban
           AND      a.deposit_date BETWEEN b.cy_start_date
                           AND     b.due_date
;Notice that table1 is the only table in the FROM clause of the sub-query, but the sub-query is correlated to table2, so we can reference columns from table2 in the sub-query.
Whenever you have a problem, post CREATE TABLE and INSERT statements for your sample data.
Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
If you're asking about a DML statement, such as UPDATE, the CREATE TABLE and INSERT statements should re-create the tables as they are before the DML, and the results will be the contents of the changed table(s) when everything is finished.
Always say which version of Oracle you're using.
Edited by: Frank Kulash on Aug 1, 2011 1:58 PM

Similar Messages

  • HT202919 I need to update my ARD admin from 3.6 to 3.7 but client is at 3.8 and it errors out. How do I work around this?

    I need to update my ARD admin from 3.6 to 3.7 but client is at 3.8 and it errors out. How do I work around this?

    This is a concern amoung many corporate users.  It's going to take somekind of policy change with apple.
    Enterprise support:
    Call enterprise support  (866) 752-7753  to create  a case ID number

  • I need to update my operating system from 10.5.8 to 10.6, I believe its the one before snow leopard and is just called leopard.

    i need to update my operating system from 10.5.8 to 10.6 on my mac mini, I believe its the one before snow leopard and is just called leopard.

    You seem to have your OS's confused.   Your profile says 10.6 but you are asking to update from 10.5.8.
    10.5.8 is Leopard.   It is also the highest level of Leopard you can achieve.
    10.6.(x) is Snow Leopard.   And 10.6.8 is the highest level you can achieve.
    If you have 10.6 then all you will need to do is download and apply the combo updater.
    If you have 10.5.8, then you will need to review the machine ... Mac OS X v10.6 Snow Leopard -Read the Technical Specifications
    Subject the machine will take it, you will then need to buy Snow Leopard from your National on-line Apple store.
    Before you start upgrading, back up your files.   If you are unsure how best to do this, the following link is hugely informative.   Most commonly used backup methods: Apple Support Communities
    Once you have upgraded to Snow Leopard, your upgrade will take you to 10.6.3 and you then will need to apply the Combo updater.  Mac OS X 10.6.8 Update Combo v1.1
    and follow with software updates to pick up the most recent security and iTunes updates.
    This will give you the best and highest level includine the App Store.
    Good luck.

  • Please tell me what media i need or i need to update to transfer videos  from iphone to pc xp ... i used to i think but cannot anymore using kodak transfer, photos are ok

    please tell me what media i need or i need to update to transfer videos  from iphone to pc xp ... i used to i think but cannot anymore using kodak transfer, photos are ok

    See the Windows XP section near the bottom of iOS: Import personal photos and videos from iOS devices to your computer
    Also, note the following quote from near the top of that section:
    Windows XP can't import video files larger than 500 MB using Camera and Scanner Wizard. You can transfer these files from your device by selecting them in My Computer and dragging or copying the files to your computer's hard drive.

  • Can we implement the custom sql query in CR for joining the two tables

    Hi All,
    Is there anyway to implement the custom sql query in CR for joining the two tables?
    My requirement here is I need to write sql logics for joining the two tables...
    Thanks,
    Gana

    In the Database Expert, expand the Create New Connection folder and browse the subfolders to locate your data source.
    Log on to your data source if necessary.
    Under your data source, double-click the Add Command node.
    In the Add Command to Report dialog box, enter an appropriate query/command for the data source you have opened.
    For example:
    SELECT
        Customer.`Customer ID`,
        Customer.`Customer Name`,
        Customer.`Last Year's Sales`,
        Customer.`Region`,
        Customer.`Country`,
        Orders.`Order Amount`,
        Orders.`Customer ID`,
        Orders.`Order Date`
    FROM
        Customer Customer INNER JOIN Orders Orders ON
            Customer.`Customer ID` = Orders.`Customer ID`
    WHERE
        (Customer.`Country` = 'USA' OR
        Customer.`Country` = 'Canada') AND
        Customer.`Last Year's Sales` < 10000.
    ORDER BY
        Customer.`Country` ASC,
        Customer.`Region` ASC
    Note: The use of double or single quotes (and other SQL syntax) is determined by the database driver used by your report. You must, however, manually add the quotes and other elements of the syntax as you create the command.
    Optionally, you can create a parameter for your command by clicking Create and entering information in the Command Parameter dialog box.
    For more information about creating parameters, see To create a parameter for a command object.
    Click OK.
    You are returned to the Report Designer. In the Field Explorer, under Database Fields, a Command table appears listing the database fields you specified.
    Note:
    To construct the virtual table from your Command, the command must be executed once. If the command has parameters, you will be prompted to enter values for each one.
    By default, your command is called Command. You can change its alias by selecting it and pressing F2.

  • I am told I need to update Flashplayer.  I have downloaded the update 5 times and installed it successfully on FireFox but Safari still says I need to update.  I have gone so far as to restart before re-opening Safari.  What am I not doing?

    I am told I need to update Flashplayer.  I have downloaded the update 5 times and installed it successfully on FireFox but Safari still says I need to update.  I have gone so far as to restart before re-opening Safari.  What am I not doing?

    Enable plug-ins.
        Safari > Preferences > Security
        Web content:
        Is the box next to "Enable plug-ins"  checked?
    Best.

  • HT201240 I there i have a apple ibook  and i need to update but i can't remember the administrator password is there way i can change the administrator the password

    I there i have a apple ibook and i need to update but i can,t remember the administrator password ,is there way i can change the administrator password,

    Changing or resetting an account password

  • Need to join the two xml type output in plsql function

    Hi,
    I need to join the two xml type output in plsql function. Could you help me out?
    Sample function:
    function func_ret_stk return xmtype
    xmloutput_stk xmtype;
    xmloutput_desp xmtype;
    begin
    xmloutput_stk := --------;
    xmloutput_desp :=---------;
    return xmloutput_stk + xmloutput_desp;
    end ;
    Thanks in Advance,

    Hello,
    this is the forum for the tool {forum:id=260}.
    Please ask your question in {forum:id=157} or {forum:id=34}
    Regards
    Marcus

  • Update Columns in Table from Other Table based on Fund Code

    Hello All!!
    Hope you are doing good!!!
    I like to update 5 columns in X Table based on fund_code. The Fund code and 5 column values come from Y Table. Please let me know how to wirte a sql statement to update all values for 5 columns in X Table. Please post me any template code.
    Thanks.

    I think you are looking for an updatable join,
    Please see the syntax below,
    UPDATE (SELECT b.col1
              FROM table1 b, table2 E
             WHERE b.col_pk = E.col_pk) T
       SET T.col1 = 0Thanks,
    G.

  • Update columns in Table A based on columns in Table B for more than 500K rows

    Guys,
    I need to update 9 columns in table A based on value from table B for for more than 500K rows.
    So what is best way to achieve this. I am thinking of writing a Procedure with cursor to update the rows of table A.
    When i googled about it, they say cursor will decrease the performance. So i have no clue how to go for this.
    Rough code which i though
    1) Procedure  with no parameter
    2) Will declare 9 variable to store value from cursor
    3) cursor will fetch row by row based on join condition between table a and table b
    4) i will pass column values from table B to variables
    5) will make an update statement for table A
    Please let me know if above method is correct or is there any other way to do this without using cursor.

    Guys,
    Below is the rough code i wrote as per my requirement. Does it look correct? As of now i dont have any platform to test it so any help with the below code is highly appreciated.  As i said i need to update more than 500K rows by matching Table
    A and Table B.  One more thing which i would like to add in below code, is to get log of all the rows that are in table B but not exist in table A.  Table A already has more than million data in it.
    Also not sure how the loop in below code willl run when @rowcount is become to zero?
    Please let me know if i need to consider performance related impact while running the script.
    GO
    SET SERVEROUTPUT ON
    CREATE PROCEDURE ONETIMEUPDATE
     DECLARE @cnt INT;
     SET @cnt = 1;
     DECLARE @MSG varchar(255);
     DECLARE @COUNT_VAR INT;
     SET @COUNT_VAR=0;
     WHILE @cnt > 0
        BEGIN
      Update TOP (50000) A
      Set A.Col1=B.Col1,
          A.COL2=B.COL2,
          A.COL3=B.COL3,
          A.COL4=B.COL4,
          A.COL5=B.COL5,
          A.COL6=B.COL6,
          A.COL7=B.COL7
      From TableA A
             Inner Join TableB B
             on A.ID = B.ID--ID
             WHERE A.Col1 <> B.Col1
                    OR A.Col2 <> B.Col2;
              SET @cnt = @@ROWCOUNT;
             IF @@ROWCOUNT=25000
               @COUNT_VAR=@COUNT_VAR + @@ROWCOUNT
               SELECT @MSG = CONVERT(varchar, @COUNT_VAR) + "Rows Updated" -- I WANT TO DISPLAY UPDATE after EVERY 25000 ROWS
              PRINT @MSG
      IF @@ROWCOUNT=0
         BEGIN    
               COMMIT
                       END
                    WAITFOR DELAY '00:00:01'  --wait for a second before the next update
                END;
     END;

  • Updating column in table using forms...

    Well guyz i had my presentation of the application today..every thing went fine ....but still they wanna add more features i.e wanna gift this application to various PM working in the company on various project ....initailly i was told that u gotta create this application for just our project now they are using my work to give it to other PMsss :( and take all the credit with no ackowledgement for me n u people who helped me a lot in building this application.... ... well they want me to create an application where in they can modify certain columns......i.e over write the existing value present in a column with a new value....
    Now suppose i have col1,col2 in table paymast how should i proceed to create trigger for when i press the button the form gets updated for the particular employee number(i mean if enter the respective info for the particular emp as soon as i press the button the old values shud b replaced by new values..
    One method that i noe is use DB wizard to create the form n then enter the value for in respective fields for the column to be updated n then press the F6 ......i dont wanna use this function...
    i wanna update the application by pressing the button
    cheers :)
    Edited by: Suhail Faraaz on Nov 15, 2009 12:26 AM
    Edited by: Suhail Faraaz on Nov 15, 2009 12:29 AM
    Edited by: Suhail Faraaz on Nov 15, 2009 12:30 AM
    Edited by: Suhail Faraaz on Nov 15, 2009 2:05 AM

    hi
    Examples:
    SELECT TXNID INTO :TXNID  FROM SAF
          WHERE
          NEXT_ATTEMPT=(SELECT MIN(NEXT_ATTEMPT)
    FROM SAF
    WHERE STATUS!='A' AND NEXT_ATTEMPT<=SYSDATE AND ATTEMPTS<10)
    AND
          STATUS!='A' AND ATTEMPTS<10 AND
          ROWNUM=1 FOR UPDATE;
       //processing==success  
       UPDATE  SAF SET  ATTEMPTS=ATTEMPTS+1, NEXT_ATTEMPT=NEXT_ATTEMPT+(10/(24*60*60))
              WHERE TXNID=:TXNID;
            commit;
        else
            rollback;
    Create trigger trigg_name
      After update of C on A
    For each row
    Is
    declare
    Pragma Autonomous_transaction;
      New_val  varchar2(27);
    Begin
    New_val := :new.C;
    Dbms_output.put_line(New_val) ;  
                /* this outputs the new value when
           evoking an update statement on Table A (Column C)  */
    If updating then
    update A set D=:new.C where C=:old.C;
           /* After compiling the trigger and evoking
              an update statement on Table A (Column C)
              the D column still not being updated */
    Commit;
    End;
    update t1
    Set t1.C1 = (Select t2.c1
    From t2
    Where t1.c3 = t2.c3),
    t1.C2 = (Select t2.c2
    From t2
    Where t1.c3 = t2.c3)
    update t2
    Set t2.C1 = (Select t1.c1
    From t1
    Where t1.c3 = t2.c3),
    t2.C2 = (Select t1.c2
    From t1
    Where t1.c3 = t2.c3)Its Correct/Helpful Please mark it.Thanks.
    sarah

  • HT4623 I need to update my IPhone 3G from v 4.2.1 to V 4.3

    My What'sup Messenger on My IPhone 3G (v 4.2.1) Stopped today & needs to update my IPhone 3G software version from 4.2.1 to version 4.3. Meanwhile, there is no version exists on apple website for v 4.3 for IPhone 3G.
    Please need your prompt support. 

    There is nothing you can do other than purchasing a new iPhone. iOS 4.2.1 is the end of the line for your phone, there are no further updates.

  • I Need to update CDPOS, CDHDR table

    Hi,
    in my system. CO01, CO02 status blank i need to update this table CDPOS, CDHDR
    I need operation release time and date. any configuration for Change documents update
    MANOJ
    Edited by: SAPPPCONSULTANT on Feb 26, 2012 9:38 AM

    pl check oss note 390635

  • I need to update my iPhone 5 from iOS 6 to iOS 7?

    I Need to update from my I phone?

    To update your iPhone 5 to IOS 7, all you have to have is a 50 % battery level or higher, and be connected to WiFi. First, you click the settings icon. Next, you'll need to go to general. Then, press software update and it should show IOS 7.1.1 or later. Press on it and agree to terms and conditions and your phone will restart. When it turns back on, IOS 7 will be downloaded.

  • I have an Iphone OS 4.3.3 and need to update with a different library than the original.

    I have an Iphone OS 4.3.3 and need to update. I have not done so since the first Itunes library used to setup my phone was done on a friend's computer and is not longer available for me. Loading to a different library requires me to erase the contents before updating. I have already come to terms with the disappointing reality of losing my media, however, will my text message history, phone contacts/numbers, notes saved in the basic built-in notes app or ANYTHING else be effected or wiped during this process? Does the backup function secure this data even though I'm using a different Library?
    Hoping there's anyone with a promising answer to this concern.
    Thanks in advance,
    MS

    App content will not be lost as long as you back up the phone to the computer you plan to restore it from. See this for advice on how to deal with your situation: Syncing to a "New" Computer or replacing a "crashed" Hard Drive

Maybe you are looking for

  • How can I retrieve emails from a deleted account?

    Hi, I've done a stupid thing. I was setting up a new account and only wanted to disable my old account but deleted the account details instead of disabling, not realising that this would actually delete the emails as well and I had most of my emails

  • Safari 5 doesn't show all images on a webpage

    Hi, I'm using Safari 5, and my Safari doesn't always show all the images on a webpage but shows a "blue question mark" instead of an image. sometime when I try to reload the webpage, the image (that was a blue question mark) appears but some other im

  • Font Conversion Problem

    Hi everyone, I have a problem with MAC fonts. I am using windows operating system and I have soem pdf files prepared in MAC. So if I copy and paste them to anywhere these fonts can not be specify by Windoes. Now I want to convert all the fonts to Tim

  • No conection between computer and scanner

    my all in one scan dos't conect to my labtop

  • HT4623 iOS 6.1.3

    is iOS 6.1.3 the latest update for ipad and was there an earlier dodgy update with a bug?