1

I am currently very new to SQL Server and I'm trying to perform a join and add a new column with data to an existing table. My tables are -

1) Enterprise Application Listing (contains Emp name, Emp ID)

2) Enterprise HR listing (contains emp name, emp id, LoginID)

I need to perform a join between the two tables to populate a new column to table 1 with the respective employees LoginID next to their employee ID. This will allow me to use that table for some further analysis. Here is my code that isn't working -

'''UPDATE EnterpriseApplicationListing INNER JOIN EnterpriseHRlisting ON EnterpriseHRlisting.emp id = EnterpriseApplicationListing.Emp ID SET EnterpriseApplicationListing.LoginID = EnterpriseHRlisting.LoginID'''

  • 1
    Check here https://stackoverflow.com/questions/982919/sql-update-query-using-joins – Jan Jun 18 '20 at 16:44
  • 1
    Does this answer your question? [SQL update query using joins](https://stackoverflow.com/questions/982919/sql-update-query-using-joins) – Jan Jun 18 '20 at 16:45

1 Answers1

0

SQL Server supports a FROM clause in UPDATE, so you want:

UPDATE eal
    SET LoginID = ehl.LoginID
    FROM EnterpriseApplicationListing eal INNER JOIN
         EnterpriseHRlisting ehl
         ON ehl.emp_id = eal.Emp_ID;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • 1
    That worked, thank you so much for the prompt response. I'm still struggling to follow SQL code in a way that makes sense, but I guess that is part of the learning curve. – Nicholas Gabriele Jun 18 '20 at 16:54