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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:29:31+00:00 2026-06-06T15:29:31+00:00

I have 2 tables Test1 and Test1Update with following structure Test1 id name address

  • 0

I have 2 tables Test1 and Test1Update with following structure

Test1
id  name address

Test1Update 
id name address

here Test1 is old table and Test1Update is just replica of Test1 table
I want to a get records with this condition,

if(Test1.id=Test1Update.id){

select macthing values from Test1Update tables,and remaining unmatched values from Test1 table
}
else if(Test1.id!=Test1Update.id)
{
select * from Test1 only
}

As a example

Test1 has data like

Test1
id  name   address
1   john    Ca
2   mary    La

and Test1Update has data like

id  name  address
1   john  Las Vega

s

Now i want to get only matching records from Test1Update table and all unmatching records from

Test1 table so final output will be

 id  name  address
 1   john  Las Vegas
 2   mary    La

It means that old entry should be replced whenever there is any match
found with Test1Update.

How can I do that using a select query or by procedure?

Show me some way .

  • 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-06T15:29:33+00:00Added an answer on June 6, 2026 at 3:29 pm

    Assuming that all the id in Test1Update are present in Test1 that can be done simply with:

    SELECT
      TEST1.ID,
      COALESCE(TEST1UPDATE.NAME, TEST1.NAME) as NAME,
      COALESCE(TEST1UPDATE.ADDRESS, TEST1.ADDRESS) as ADDRESS
    FROM TEST1
    LEFT JOIN TEST1UPDATE ON TEST1.ID = TEST1UPDATE.ID
    

    See it work here: http://sqlfiddle.com/#!3/4a1f2/3/0

    With the LEFT JOIN, if there is no matching entry in TEST1UPDATE, TEST1UPDATE.NAME and TEST1UPDATE.ADDRESS are null.
    COALESCE gives you the first non null argument, so you’ve got the values from TEST1UPDATE if present, else from TEST1.

    Edit for the UNION solution:

    If there are a lot of fields, the COALESCE solution might be a bit verbose and you would like to use a UNION:

    SELECT *
    FROM TEST1UPDATE
    INNER JOIN TEST1 ON TEST1.ID = TEST1UPDATE.ID
    
    UNION
    
    SELECT *
    FROM TEST1
    LEFT JOIN TEST1UPDATE ON TEST1.ID = TEST1UPDATE.ID
    WHERE TEST1UPDATE.ID IS NULL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with following structure and test records: +--------+--------+---------+ | vid | number
I have table data like this id id1 name 1 1 test1 1 1
I've got tables like: table A id name email 1 test1 ex@ex.com 2 test2
I have two tables test1 { id, name } and test2 { id, name,
So, I have three tables, table local, table item and table item_local. Here is
I have a table defined by the following SQL: CREATE TABLE test ( id
I have the following table: CREATE TABLE TEST(ID TINYINT NULL, COL1 CHAR(1)) INSERT INTO
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
Here is the sample data for test table I have [childId] [parentId] [present] 1
I have two tables in my database: test1 which looks like: ID pubmed_ID -------------------

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.