I have two tables in different databases on the same database server.
Both the databases have the same structure, but different data. Database1 (Test1) is the latest
UPDATE Employee SET Empid=emp3.empid
FROM EMP_Employee AS emp3
WHERE Employee.Empid=emp3.empid
If the two databases are on the same server, you should be able to create a SQL statement something like this:
UPDATE Test1.dbo.Employee
SET DeptID = emp2.DeptID
FROM Test2.dbo.Employee as 'emp2'
WHERE
Test1.dbo.Employee.EmployeeID = emp2.EmployeeID
From your post, I'm not quite clear whether you want to update Test1.dbo.Employee
with the values from Test2.dbo.Employee
(that's what my query does), or the other way around (since you mention the db on Test1
was the new table......)
Try a query like
INSERT INTO NEW_TABLENAME SELECT * FROM OLD_TABLENAME;
update test1 t1, test2 t2
set t2.deptid = t1.deptid
where t2.employeeid = t1.employeeid
you can not use from keyword for the mysql
use test1
insert into employee(deptid) select deptid from test2.dbo.employee
update t2
set t2.deptid = t1.deptid
from test1 t1, test2 t2
where t2.employeeid = t1.employeeid