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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:36:03+00:00 2026-06-05T22:36:03+00:00

I have two similar tables table_a and table_b table_a is my current data and

  • 0

I have two similar tables table_a and table_b
table_a is my current data and I need to update this info using table_b which is a temporary table. The only difference between the two is table_a has a password field that table_b will not have.

I am trying to do a couple of things.

1.Compare the data based on the "user_id" field. 
2. If there is a user_id not found in table_b but there is one in table_a remove that row in table_a
3. If there is a user_id in table_b that is not found in table_a add that row of data to table_a
4. If the user_id is found in both then check two of the fields "email" and "job_code" and make sure they are both whatever table_b says.

Should I do this in separate MySQL statements in the order I have numbered above? below is my try at the above statements. Any help or troubleshoot is greatly appreciated. Thanks!

Statement 1:

SELECT * FROM table_a
WHERE table_a.user_id
NOT IN (
SELECT table_b.user_id
FROM table_b
WHERE table_a.user_id=table_b.user_id
)  // But how do I delete those records that are selected?

Statement 2:

SELECT * FROM table_b
WHERE table_b.user_id
NOT IN (
SELECT table_a.user_id
FROM table_a
WHERE table_a.user_id=table_b.user_id
) //How do I Insert these records that I have in table_b but not in table_a

Statement 3:

SELECT email FROM table_b
WHERE table_b.user_id = table_a.user_id,
AND table_b.email != table_a.email  //now I need to update table_a with the emails from table_b
  • 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-05T22:36:09+00:00Added an answer on June 5, 2026 at 10:36 pm

    Statement #1

    DELETE A.*
    FROM table_a A
    LEFT JOIN table_b B
    USING (user_id)
    WHERE B.user_id IS NULL;
    

    Statement #2

    INSERT INTO table_b (column1,column2,...,columnN)
    SELECT A.column1,A.column2,...,A.columnN
    FROM table_b B LEFT JOIN table_a A
    USING (user_id)
    WHERE A.user_id IS NULL;
    

    Statement #3

    UPDATE table_a A INNER JOIN table_b B USING (user_id)
    SET A.email = B.email,A.job_code = B.job_code;
    

    UPDATE 2012-06-19 11:54 EDT

    A and B are just aliases for the table.

    For example, the query of Statement #3 could have been written like the following:

    UPDATE table_a as A INNER JOIN table_b as B USING (user_id)
    SET A.email = B.email,A.job_code = B.job_code;
    

    or with no aliases whatsoever, like this:

    UPDATE table_a INNER JOIN table_b USING (user_id)
    SET table_a.email = table_b.email,table_a.job_code = table_b.job_code;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two MySQL tables with a similar structure. i.e. Table_A - Col1, Col2,
I have two very similar tables in our database, and I need to write
I have two tables with similar columns - let's say table A with column
I have two tables that have virtually identical content and very similar structure. They
If I have two tables in mysql that have similar columns... TABLEA id name
I have two tables looking like this: A B id_attr value id id_attr value
I have two tables, mytableA and mytableB. MytableA looks like this ColumnA|Columnb Apple|fruitstand Pear|fruitstand
I currently have two tables similar to users and programs that are linked through
I have two tables with similar information. Let's call them items_a and items_b .
I have a two tables similar to the following: I am attempting to create

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.