Hi I have current salary table callsed jan, columns are employeename, employeeid and Jansalary. I have to update Feb salary to January table. my code is:
update jan
set jan.salary=feb.salary
from jan
inner join feb
on feb.employeeid=jan.employeeid
my question is if feb have new employee salary data, should I use right join?
Your query is incorrect you can not put UPDATE after FROM it will gives you syntax incorrect.
The correct query is something like this :
update jan, feb
set jan.salary=feb.salary
where feb.employeeid=jan.employeeid;
If you have a new employee salary data on Feb you have two options :
Option 1 : You dont want to have the new employee salary data on Jan so in this case nothing to do because your join is based on employeeid Option 2 : You want to replicate the new employee salary data on Jan so this query can do this :
INSERT INTO `feb` (`employeeid`,`employeename`,`salary`)
SELECT DISTINCT(feb.employeeid), employeename, salary
FROM feb
WHERE feb.employeeid NOT IN (SELECT jan.employeeid FROM jan);
Your design is bad the best is just to create one table called salary
and you put the month as filed on this table :
salary table
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.