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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:39:59+00:00 2026-05-23T09:39:59+00:00

I have 3 tables, ‘old’, ‘new’ and a ‘result’ table (from a phonebook database),

  • 0

I have 3 tables, ‘old’, ‘new’ and a ‘result’ table (from a phonebook database), they have the same structure and nearly the same entries.

old:
ID  | name               | number | email | ...
----+--------------------+--------+-------+-----
1   | foo                | 123    | ...
2   | bar                | 456    |
3   | entrry with typo   | 012345 |
4   | John Doe           | 123345 |

new:
ID  | name               | number | email | ...
----+--------------------+--------+-------+-----
1   | foo                | 123    | ...
2   | bar                | 456    |
3   | entry without typo | 012345 |
4   | John Doe           | 12345  |
5   | newly added entry  | 09876  |

From this ‘new’ table I would like to select all rows that are different from the ‘old’ table, so the result would be:

result:
ID  | name               | number | email | ...
----+--------------------+--------+-------+-----
3   | entry without typo | 012345 | ...
4   | John Doe           | 12345  |
5   | newly added entry  | 09876  |

including all entries that have changed data plus all entries that don’t appear in ‘old’ table…

Not only to make it more complicated, there are about 10 columns in those tables (including ID, name, number, email and several flags and other info).

Is there any most performant solution for doing this or will I have to compare each column with a new query..?

  • 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-23T09:40:00+00:00Added an answer on May 23, 2026 at 9:40 am

    You’ll have to do some comparison on the old records for correctness but I think this is the most straight forward solution.

    Update I was a little confused about icluding all entries that have changed data plus all entries that don’t appear in ‘old’ table… So I added the where and modified the join clause

    insert into result (id, name, number, email, ...)
    select new.id, new.name, new.number, new.email, ...
    from new
    LEFT JOIN old
    ON new.ID = old.id
    WHERE 
    old.ID is null
    OR
    ( new.name <> old.name
      or
      new.number <> old.number
      or
      new.email <> new.email
      ...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the database we have tables called Sites, Organisations, Person, Department have the same
I have tables with following structure: -- Table structure for table `temp_app` -- CREATE
In my database I have tables that define types for example Table: Publication Types
I have tables in a MySQL database like this... CREATE TABLE `someUserTable` ( userId
I have tables linked by FK, I query on the first table using entity
I have tables: Teachers and Students. We have a SpecialProjects Table where Teachers and
I have tables like this: from sqlalchemy import Column, Integer, select from sqlalchemy.ext.declarative import
have tables like this Table checklist idCardno name permAddress datetime Table persons name idcardno
I have tables item and store (it's a store management system). item table has
I have tables foo and bar: create table foo(a int, b varchar(10), primary key

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.