Results 1 to 2 of 2

Thread: Oracle syntax for update with a value from two other tables

  1. #1

    Thread Starter
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Oracle syntax for update with a value from two other tables

    I have a table I need to update with a value from two other tables. What's the syntax? Obviously not the same as SQL Server. I may have figured out the need for a subquery, but how do I link the value returned from the subquery to the table being updated?

    Table 1 - needs to be updated
    Table 2 - links to Table 1
    Table 3 - links to Table 2 and has the value needed for the update

    ' here's a stab at it but it's not quite right:
    UPDATE Table1
    SET myDateDueValue = (SELECT P.DATEDUETOREP from Table2 U, Table3 P
    WHERE P.PROPOSALNUMBER = U.RP_ProposalNumber AND U.RP_PROPOSALNUMBER <> 0) SQ
    WHERE REQUESTID = SQ.REQUESTID;

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Oracle syntax for update with a value from two other tables

    Usual one is something like :

    Code:
    Update Table1, (SELECT P.DATEDUETOREP from Table2 U, Table3 P 
    WHERE P.PROPOSALNUMBER = U.RP_ProposalNumber AND U.RP_PROPOSALNUMBER <> 0
    ) SQ 
    WHERE table1.REQUESTID = SQ.REQUESTID
    SET myDateDueValue = sq.DATEDUETOREP
    Please note - I may have got that second where clause in the wrong place...

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width