I have table Employee. I need to update manager id using excel sheet (to get value from excel I have written below query)
Employee
Emp_ID Emp_Code Name ManagerID
1 1111 xyz 2
2 2222 abc 3
3 3333 mno 2
I have written query like this
UPDATE Employee SET ManagerID = Emp_ID from Employee inner join Employee AS MGR
on Employee.emp_id=MGR.emp_id WHERE emp_code='1111'
but its not updating the correct value
Based on what you’ve told us, you don’t need a self join at all, i.e. you can simply update an employee’s manager id directly
etc
However, if you mean that you need to perform the update given only the emp_code of the employee and the emp_code of the manager (i.e. without the Manager’s PK), then you can use a subquery (uncorrelated), e.g.
If you then later need to add a query showing the employee and his / her manager (and assuming that the ultimate boss doesn’t have a manager), you can do the self join like so: