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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:20:43+00:00 2026-06-04T20:20:43+00:00

I am comparing two tables A and B. A and B are months (we

  • 0

I am comparing two tables A and B. A and B are months (we will go with JAN and FEB).
FEB has updated data that belongs in JAN.

I need to update the data like so

UPDATE A
SET A.x = B.x, A.y = B.y, A.z = B.z
FROM JAN A, FEB B
WHERE (A.x <> B.x OR A.y <> B.y OR A.z <> B.z) AND A.PK = B.PK

Now I want the above to not take place on the Original JAN table.
Should I go about it this way? Or is there a better way?

SELECT *
INTO JAN_UPDATED
FROM JAN

UPDATE A
SET A.x = B.x, A.y = B.y, A.z = B.z
FROM JAN_UPDATED A, FEB B
WHERE (A.x <> B.x OR A.y <> B.y OR A.z <> B.z) AND A.PK = B.PK

EDIT: I want all of the original values + the updates in the new table

EDIT: Added PK

  • 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-04T20:20:45+00:00Added an answer on June 4, 2026 at 8:20 pm

    Using an outer join, you could select the data into a new table and update them along the way. Here’s how:

    SELECT    A.PK,
              COALESCE(B.x, A.x) AS x,
              COALESCE(B.y, A.y) AS x,
              COALESCE(B.z, A.z) AS x,
              other columns as necessary
    INTO      JAN_UPDATED
    FROM      JAN A
    LEFT JOIN FEB B ON A.PK = B.PK AND (A.x <> B.x OR A.y <> B.y OR A.z <> B.z)
    

    The left part of the join, the JAN table, will return all the JAN rows, and the right part of the join, FEB, will only return matching rows, those which are different from their counterparts in JAN. When there’s no match, the right part’s columns will be filled with NULLs. Now, when pulling values, the COALESCE() function is used for x, y, and z: the FEB version is tried first, and if it is NULL (meaning this is a non-matching JAN row, the one that has no updates in FEB), then the JAN party (the unchanged value) is used instead.

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

Sidebar

Related Questions

I have two tables in MySQL that I'm comparing with the following attributes: tbl_fac
I am comparing between two tables first column each. If there is find a
Possible duplicate : comparing-two-arrays I have two NSArray and I'd like to create a
Possible Duplicate: Comparing Two Arrays Using Perl I am trying to find elements that
I need an algorithm or a standard library function for comparing two vector elements,
My problem is I am comparing two records from different tables and deleting those
I am trying to compare two tables to find rows in each table that
I have two tables with lists of files: table1 has column1 with file names
I am attempting to join two tables by comparing and matching values in separate
I have a SQL select statement which is comparing two tables. I am getting

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.