Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4616620
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:00:29+00:00 2026-05-22T02:00:29+00:00

FOR v2 AS c2 CURSOR FOR SELECT he.MyPrimary, he.SomeCode, he.SomeName, pe.MyPrimary FROM SomeTable he

  • 0
FOR v2 AS
    c2 CURSOR FOR
        SELECT he.MyPrimary, he.SomeCode, he.SomeName, pe.MyPrimary
        FROM SomeTable he
            INNER JOIN AnotherTable pe
                ON (he.ColOne = pe.FooOne
                    AND he.ColTwo = pe.ColTwo
                    AND he.ColThree = pe.FooOne
                    AND he.SomeCode = pe.SomeCode)
        WHERE he.relevancy = 1 AND he.ColThree = '2011-01-05' AND he.ColFive = 9
DO
    UPDATE AnotherTable SET match = he.MyPrimary, FooTwo = he.SomeCode, SomeName = he.SomeName WHERE MyPrimary = pe.MyPrimary;  

END FOR;

I have the above code and I’m trying to do this without using cursors but I’m not sure how to do an UPDATE statement with an INNER JOIN. Basically, what I’d like to do is join two tables SomeTable and AnotherTable then based on some column values from SomeTable, copy the value to a similar column in AnotherTable. I’m using DB2.

EDIT: I was just looking into this: INNER JOIN in UPDATE sql for DB2

Would it make sense to do something like this instead:

UPDATE
  SomeTable pe
SET
  match = (SELECT he.MyPrimary FROM SomeTable he WHERE he.ColOne = pe.FooOne
                            AND he.ColTwo = pe.ColTwo
                            AND he.ColThree = pe.FooOne
                            AND he.SomeCode = pe.SomeCode ),

  FooTwo = (SELECT he.SomeCode FROM SomeTable he WHERE he.ColOne = pe.FooOne
                            AND he.ColTwo = pe.ColTwo
                            AND he.ColThree = pe.FooOne
                            AND he.SomeCode = pe.SomeCode )
WHERE
  he.relevancy = 1 AND he.ColThree = '2011-01-05' AND he.ColFive = 9
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:00:30+00:00Added an answer on May 22, 2026 at 2:00 am

    As your link mentioned, the ISO/ANSI standard does not allow for a join in an Update statement outside of its use in a subquery. Thus, you have to either do multiple Update statements, or so a subquery for each column.

    Update AnotherTable 
    Set match = (
                    Select he.MyPrimary
                    From SomeTable he
                    Where he.ColOne = AnotherTable.FooOne
                        And he.ColTwo = AnotherTable.ColTwo
                        And he.ColThree = AnotherTable.FooOne
                        And he.SomeCode = AnotherTable.SomeCode
                        And he.relevancy = 1 
                        And he.ColThree = '2011-01-05' 
                        And he.ColFive = 9
                    )
        , FooTwo =  (
                    Select he.SomeCode
                    From SomeTable he
                    Where he.ColOne = AnotherTable.FooOne
                        And he.ColTwo = AnotherTable.ColTwo
                        And he.ColThree = AnotherTable.FooOne
                        And he.SomeCode = AnotherTable.SomeCode
                        And he.relevancy = 1 
                        And he.ColThree = '2011-01-05' 
                        And he.ColFive = 9
                    )
        , SomeName =    (
                        Select he.SomeName
                        From SomeTable he
                        Where he.ColOne = AnotherTable.FooOne
                            And he.ColTwo = AnotherTable.ColTwo
                            And he.ColThree = AnotherTable.FooOne
                            And he.SomeCode = AnotherTable.SomeCode
                            And he.relevancy = 1 
                            And he.ColThree = '2011-01-05' 
                            And he.ColFive = 9
                        )
    Where Exists    (
                    Select 1
                    From SomeTable he
                    Where he.ColOne = AnotherTable.FooOne
                        And he.ColTwo = AnotherTable.ColTwo
                        And he.ColThree = AnotherTable.FooOne
                        And he.SomeCode = AnotherTable.SomeCode
                        And he.relevancy = 1 
                        And he.ColThree = '2011-01-05' 
                        And he.ColFive = 9
                    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

cursor.execute(SELECT user_id FROM myapp_location WHERE\ GLength(LineStringFromWKB(LineString(asbinary(utm), asbinary(PointFromWKB(point(%s, %s)))))) < %s\ ,(user_utm_easting, user_utm_northing, 500)); This
I have the cursor with the query statement as follows: cursor.execute(select rowid from components
I have a stored procedure DECLARE cursor FOR SELECT [FooData] From [FooTable]; OPEN cursor
I have this code: cursor.execute( ''' SELECT id,DISTINCT tag FROM userurltag ''') tags =
We can declare a cursor like this DECLARE cur1 CURSOR FOR SELECT id,data FROM
I am trying to do the following query: cursor.execute(SELECT DISTINCT(provider) FROM raw_financials WHERE vendor_id=%s
If I have a simple query like: OPEN cursor FOR SELECT USER_ID FROM USER_TABLE
I have a simple query in a cursor Cursor some_cursor IS select sum(some_field) from
conn = MySQLdb.connect(host=IP,user='john',passwd='ab2nng',db='mydb') cursor = conn.cursor() #this works. cursor.execute(select * from crawl_log) res =
Given following snippet (MS SQL): DECLARE UpdateList CURSOR FOR SELECT MyColumn FROM MyTable OPEN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.