I am trying to create an sql statement that updates a field in table A with a value from table B where the key of the two is equal. Lets say the struture is as follows
Table A Table B
=============== ===============
ID (N) ID (N)
Description (C) Description (C)
data may look like thise
Table A Table B
================== ===================
ID Description ID Description
1 HGT 1 empty
2 ABC 2 empty
3 LLK 3 empty
4 PIY 4 empty
When I run the query the data in table should be the same as A where the ID fields match.
I thought it should go something like (ignore space in name):
The mosy annoting thing about this is I have done something like this before and for the love of god have forgotten how and where I did it. I remember something about making the subquery and alias so it can do the when but I can't remember how. Any help would be greatfully accepted.
Mark Davies
Warwickshire County Council
Table A Table B
=============== ===============
ID (N) ID (N)
Description (C) Description (C)
data may look like thise
Table A Table B
================== ===================
ID Description ID Description
1 HGT 1 empty
2 ABC 2 empty
3 LLK 3 empty
4 PIY 4 empty
When I run the query the data in table should be the same as A where the ID fields match.
I thought it should go something like (ignore space in name):
Code:
UPDATE tableb SET description = (SELECT description FROM tablea) where a.id = b.id
The mosy annoting thing about this is I have done something like this before and for the love of god have forgotten how and where I did it. I remember something about making the subquery and alias so it can do the when but I can't remember how. Any help would be greatfully accepted.
Mark Davies
Warwickshire County Council