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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:26:05+00:00 2026-06-09T18:26:05+00:00

I have table Employee. I need to update manager id using excel sheet (to

  • 0

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

  • 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-09T18:26:07+00:00Added an answer on June 9, 2026 at 6:26 pm

    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

    UPDATE Employee  
        SET ManagerID = 2 
        WHERE  emp_code='1111'
    

    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.

    UPDATE Employee  
        SET ManagerID = (SELECT manager.Emp_Id 
                           FROM Employee manager 
                           WHERE manager.emp_code = '2222') -- Manager's emp_code
        WHERE  emp_code='1111' -- Employee to update's emp_code
    

    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:

    SELECT emp.emp_code as EmployeeCode, emp.name as EmployeeName, 
           mgr.emp_code as ManagerEmpCode, mgr.name as ManagerName
    FROM Employee emp 
       LEFT OUTER JOIN Employee mgr 
       ON emp.ManagerId = mgr.Emp_Id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following query to list the employees of two table. i need
Suppose I have table Person table Employee, which inherits Person. I want to get
I am using the netbeans and mysql. I have a table named employee with
I have an employee table, with the following data. For a particular manager, i
Hi i need help with a query I have a table Where Jobs and
I have an employee table which contains a manager ID as a column. If
I have a table that contains employee numbers. They need to be 5 numbers
I have an excel sheet where in the data looks similar to the table
I have a table that holds project manager and project director employee id's e.g
I have a table (employee) like below: EMPNO ENAME JOB MGR HIREDATE SAL COMM

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.