2

I have two table let's name A and B having following field :

TABLE A

| ID | COUNTRY_CODE | COUNTRY_NAME | FIRST_NAME | LAST_NAME |

TABLE B

| ID | COUNTRY_CODE | COUNTRY_NAME |

Now I need to update country_code field from Table A whose value is to be fetched from Table B.

The pseudo-code is something like this :

for all rows in Table A :
  set A.country_code = (select B.country_code from B where B.country_name = A.country_name
Fahmi
  • 36,607
  • 5
  • 19
  • 28
Paras
  • 2,587
  • 4
  • 35
  • 67

2 Answers2

1

Use update with JOIN

update TableA A
inner join tableB B on B.country_name = A.country_name
set A.country_code=B.Country_code
Fahmi
  • 36,607
  • 5
  • 19
  • 28
0

No need join, just try sql as below:

update TableA set country_code = B.country_code from TableB B where A.country_name = B.country_name 
Shawn.X
  • 1,233
  • 5
  • 15