Fahad
Fahad

Reputation: 99

Match Same column and replace the values

I have two tables City with codes and other is the employees table.The issue while inserting was that instead of the Code of the city the actual name was inserted.I need to replace them with the codes.I have like 2400 employees.What kind of sql-query I should write to replace all the names of the city in the Employe table with the actual codes of the cities

Upvotes: 0

Views: 74

Answers (2)

Gökhan Girgin
Gökhan Girgin

Reputation: 1164

UPDATE e SET
City = c.Code
FROM
Employe AS e 
INNER JOIN City AS c ON c.City = e.City

Upvotes: 1

chetan
chetan

Reputation: 2886

UPDATE employees a, City b 
SET a.code = b.code
WHERE b.name = a.code;

Upvotes: 0

Related Questions