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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:38:54+00:00 2026-06-11T10:38:54+00:00

TableA : ID, mail, team, [other columns] TableB : ID, mail, team, [other columns]

  • 0

TableA :
ID,
mail,
team,
[other columns]

TableB :
ID,
mail,
team,
[other columns]

ID is the primary key in both tables. I need to work through every row in TableB and :

  1. If ID doesn’t exist in TableA, insert new row – using columns
    ID,mail,team (only)
  2. If ID does exist in TableA, update row with new value for mail (only)
  3. ID’s that exist in TableA but not TableB row should
    remain unchanged

I have :

INSERT INTO tablea (id,mail,team) (SELECT id,mail,team FROM tableb)
ON DUPLICATE KEY update tablea SET tablea.mail=tableb.mail;

This doesn’t work – I think I need a join to make the last SET command valid, but not sure on this part, can anyone help?

Many 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-06-11T10:38:56+00:00Added an answer on June 11, 2026 at 10:38 am

    As documented under INSERT ... ON DUPLICATE KEY UPDATE Syntax:

    You can use the VALUES(col_name) function in the UPDATE clause to refer to column values from the INSERT portion of the INSERT ... ON DUPLICATE KEY UPDATE statement. In other words, VALUES(col_name) in the ON DUPLICATE KEY UPDATE clause refers to the value of col_name that would be inserted, had no duplicate-key conflict occurred. This function is especially useful in multiple-row inserts.

    Therefore:

    INSERT INTO tablea (id, mail, team)
    SELECT id, mail, team FROM tableb
    ON DUPLICATE KEY UPDATE mail = VALUES(mail)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called TableA whch has a foreign key from TableB and
I have 2 Tables, User and Mail. In User Table i have 2 columns
I have two tables users with columns: uid, name, mail, etc users_roles with columns:
I've 3 tables. Users (id, mail, username, etc..) Practices (id, name) UsersPractices (userId, practiceId)
I have a table TableA with two columns: MyName nvarchar(100) and MyDateTime DateTime .
SELECT * FROM TableA INNER JOIN TableB ON TableA.name = TableB.name SELECT * FROM
i have two mysql tables tableA colA1 colA2 1 whatever 2 whatever 3 whatever
I have a table of users where each row contains their names, e-mail address,
I've created a database an a table (Mail) having 2 columns: id INTEGER, content
Question: I have a table with the columns ID, Name, Prename, Mail Mail contains

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.