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
  • 37,315
  • 5
  • 22
  • 31
Paras
  • 3,191
  • 6
  • 41
  • 77

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
  • 37,315
  • 5
  • 22
  • 31
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,323
  • 6
  • 15