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 6877855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:39:03+00:00 2026-05-27T04:39:03+00:00

I am going to explain it as simple as possible. Now I have a

  • 0

I am going to explain it as simple as possible. Now I have a table_1 which has price and itemId. I also have another table table_2 which has totalprice,itemId.

What I want to do is to sum all price from table_1 grouped by itemId and update that sum of price in table_2 with itemId key as the common column.

The price per itemId summed from table_1 should update the totalprice column in table_2.

Is that possible ? Thank you.

SQL Server 2008 R2

  • 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-27T04:39:04+00:00Added an answer on May 27, 2026 at 4:39 am

    Yes is it possible. You can do like this:

    update T2
    set totalprice = T1.totalprice
    from Table_2 as T2
      inner join (select sum(price) as totalprice,
                         itemid
                  from Table_1
                  group by itemid) as T1
        on T2.itemid = T1.itemid
    

    https://data.stackexchange.com/stackoverflow/q/119388/

    If you don’t already have all itemid’s in table_2 you can use a merge to update the existing rows and add a new row if it is missing.

    merge Table_2 as T2
    using (select sum(price) as totalprice,
                  itemid
           from Table_1
           group by itemid) as T1
    on T1.itemid = T2.itemid
    when matched then 
      update set totalprice = T1.totalprice
    when not matched then 
      insert (totalprice, itemid) 
      values(T1.totalprice, T1.itemid);
    

    https://data.stackexchange.com/stackoverflow/q/119389/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am going to make a simple Alarm Clock, I have user interface and
I have been going crazy over a problem with my tab control. It has
I'm going to try to explain this in simple terms, because it's probably shorter
Ok, I'm going to try to explain this one as easy as possible! I'm
I have a table that contain one primary key. When I run EXPLAIN SELECT
Can anyone explain whats going on 'under the hood' with textRanges in IE/javascript? What
This is going to be hard to explain but I'll try my best. I
I'm going to try to explain the problem. I am getting a string containing
Can someone explain the nuts and bolts of what's really going on under the
This is going to be a little tricky to explain. I'm trying to write

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.