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

  • SEARCH
  • Home
  • 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 8682317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:44:32+00:00 2026-06-12T21:44:32+00:00

I have table1 as below: Col1 Bal ——————- 1 0 2 0 3 0

  • 0

I have table1 as below:

Col1    Bal
-------------------
 1       0
 2       0
 3       0
 4       0

Col1 is the key here.

I have table2 as below:

Col1    Bal    Date
---------------------
 1       5      x
 1       10     y
 1       7      z
 3       8      p
 3       9      m

Col1 is the join column in both tables.

I want to update bal in first table with sum of bal in 2nd table.

What would be the sql statement for this:

update table1 a set a.bal=(select sum(b.bal) from table2) where 

and I am lost!

After update, table1 should be:

Col1    Bal
-------------------
 1       22
 2       0
 3       17
 4       0
  • 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-06-12T21:44:34+00:00Added an answer on June 12, 2026 at 9:44 pm

    From the documentation, it looks like you can use table aliases in DB2:

    update  table1 a 
    set     bal = coalesce(
            (
            select  sum(b.bal) 
            from    table2 as b
            where   a.col1 = b.col1
            ), 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables as below: Student: oneID (primary key), col1, col2, col3, subId,
I have table1 (col1,col2) and table2(col1,col2) as given below/ Now i need to replace
Currently i have a table like below Table1 hTeam-----aTeam-------date--- 3----------5 ------2012/01/01 4 -------- 7
I have four tables in my database and i want to join that's and
I have a query below: select col1, col2, . . . coln from table1
Situation is as below. I have a table like here: Col1 Col2 Col3 Col4
I have two tables table1 and table2. Table2 is having less number of rows
I have a table as below: table1 col1 col2 col3 1 A 1 2
I have a table like below: COL1 | COL2 | COL3 ______________________ ITEM1 |
I have created one table using the below command: create table Table1( Id int

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.