MySQL: Trying to populate data into one column from another table

It sounds like you already have data in TableA that you want to update. If that is the case, you need to use an UPDATE statement. Here's an example:

UPDATE TableA A
SET EMPLOYEE_ID =
  (SELECT EMPLOYEE_ID
   FROM TableB B
   WHERE B.First_name = A.First_name
   AND B.Last_name = A.Last_name)
WHERE EXISTS
  (SELECT EMPLOYEE_ID
   FROM TableB B
   WHERE B.First_name = A.First_name
   AND B.Last_name = A.Last_name)

Question: Are first and last name guaranteed to be unique?

Also, this needs to be an update.

UPDATE TableA A
SET a.employee_id = (SELECT employee_id FROM TableB WHERE first_name = a.first_name AND last_name = a.last_name)
WHERE EXISTS (SELECT 1 FROM TableB WHERE first_name = a.first_name AND last_name = a.last_name)

Tags:

Mysql

Sql

Merge