Click to See Complete Forum and Search --> : A Little question on SQL


yslee2
May 31st, 2006, 10:20 PM
How do I write a query to update column A of Table1, setting the value of column A to be the value of column A of Table2

Table1
col A col B(key)
100 1
200 3
300 2

Table2
col A col B(key)
10 2
20 3
30 4

Table1 after modification
col A col B
100 1
20 3
10 2

thanks

hspc
June 2nd, 2006, 08:08 AM
This works on MS SQL server
Update Table1
Set A = (Select A From Table2 Where B=Table1.B)

WarlockSoul
June 2nd, 2006, 08:30 AM
Hi,

You should use the 'Update' function in SQL e.g.

Update Table1
Set
Table1.colA = Table2.colA
From Table1, Table2
Where
Table1.colB = Table2.colB