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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:18:10+00:00 2026-06-09T08:18:10+00:00

I am new to SQL in general and even newer to MS SQL. I

  • 0

I am new to SQL in general and even newer to MS SQL. I apologize if the title isn’t clear on what I want.

I have two tables an old one that I want to derive data from into a new table. The tables have the exact same columns but different number of rows. The new table has multiple copies of each value in the old table, which only has 2 occurences. see below comparison of two columns: letter and amount.

New table:

A  0 
A  0
A  0
B  0
B  0

old table:

A  12
A  0
B  10
B  0
C  23

What I want to achieve is adding the values of the amount column from the old table into just the first occurence of the leter in the new table like so:

A  12 
A  0
A  0
B  10
B  0

Inner join causes all the values to be filled ( so all the A’s are set to 12).

  • 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-09T08:18:11+00:00Added an answer on June 9, 2026 at 8:18 am

    try this:

    DECLARE @test1 TABLE(col1 varchar(2),idn int)
    insert into @test1
    VALUES('A',0),
    ('A',0),
    ('A',0),
    ('B',0),
    ('B',0)
    
    DECLARE @test2 TABLE(col1 varchar(2),idn int)
    insert into @test2
    VALUES('A',12),
    ('A',0),
    ('B',10),
    ('B',0),
    ('C',23)
    
    
    ;WITH CTE as (select *,ROW_NUMBER() over (partition by col1 order by col1) as rn from @test1)
    
    update c SET c.idn=b.idn
    from CTE c inner join (select col1,SUM(idn) as idn from @test2
    group by col1) b
    on c.col1 = b.col1 
    where c.rn=1
    
    select * from @test1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new SQL queries, and I'm trying to join two tables in order
I have two tables in a one to many relationship. (products and qty break
I've got an MS SQL database with 3 inherent tables. A general one called
So I'm very new to working in SQL in general, let alone rails but
I am writing some new SQL queries and want to check the query plans
I need to create an entirely new Sql Server 2008 database and want to
I`m new to sql and have been stuck on the following issue for almost
I'm new to SQL. I have a simple problem with getting the results from
I'm working with SQL Server and I'm pretty new to SQL in general, so
I'm new to ASP.net, the ViewState, and C# in general. I have some code

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.