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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:17:13+00:00 2026-05-20T07:17:13+00:00

I have 2 tables in the DB. each with Name column and Count column

  • 0

I have 2 tables in the DB. each with “Name” column and “Count” column each.

I would like to update the Count column in the second table from the Count in the first table only where the “Name” columns are equal.

Example:

First Table:

Name Count

jack 25
mike 44

Name Count

jack 23
mike 9
david 88

Result (the second table would look like that…)

Name Count

jack 25
mike 44
david 88

NOTES:
1. Both tables are huge. (although the second table is bigger…)
2. The update must be as fast as possible…
(if there are more options other than stored procedures, i would love to hear.)
3. “Count” defined as bigint while “Name” as nvarchar(100)
4. the “Count” field in the first table is always bigger than the equivalent in the
second table.

I think that there are more options (other than stored procedure) maybe with MERGE or TRANSACTION as long as it will be the fastest way…

Thanks!

  • 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-20T07:17:14+00:00Added an answer on May 20, 2026 at 7:17 am

    The best way would be to keep it simple

    UPDATE Table2
    SET Count = t1.Count
    FROM Table1
    WHERE Table2.Name = Table1.Name 
      AND Table2.Count <> Table1.Count
    

    If the performance of this query is not satisfactory due to the size of your tables the best solution would be to partition the tables based on the name field. The query can then be run from different threads at the same time with and extra filter based on Name to satisfy the partition function.

    For example: (assuming name is a varchar(20) column)

    UPDATE Table2
    SET Count = t1.Count
    FROM Table1
    WHERE Table2.Name = Table1.Name 
      AND Table2.Count <> Table1.Count
      AND Table2.Name between cast('Jack' as varchar(20)) 
                          and cast('Mike' as varchar(20))
    

    (The cast on the strings is a big help for Sql Server to properly do partition elimination.)

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

Sidebar

Related Questions

Let's say I have three tables (with the columns in each): USERS: id, name,
I have three tables with 5 columns each. They can grow upto 15 rows
I have a flow layout. Inside it I have about 900 tables. Each table
I have created script to find selectivity of each columns for every tables. In
I have a table with two child tables. For each record in the parent
I have been trying to find out total count of rows in each tables
I have a employee draw type application, the tables look like: Employee (ID, name,
I have a table that has a lot of duplicates in the Name column.
I have a (mysql) database table with the following columns: NAME | String (Unique)
I have a simple referrers table with three columns: Referrer //string name of partner

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.