Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update a column if this two column matches?

Status
Not open for further replies.

aaa8888

MIS
Jan 28, 2005
5
US
Hi, I'm having troubles writting a SQL query to update a column if the other two column's field are the same. Lets say i have two tables, table "A" and table "B". Table "A" has two columns "1" and "2" and table "B" has two columns "3" and "4". Suppose that Column "1" from table "A" and column "3" from table "B" has the same values. How do i run a update query to fill in the data in column "4" with data from column "2" if the data in column "1" matches column "3". I know this sounds confusing but this is the best i can come up with. I been trying to populate the data by using the update and where exist query but couldn't get the query to run.
 
Not a problem. You want something like this.

Code:
update TableB
  set TableB.Col4 = TableA.Col2
from TableA
where TableA.Cola = TableB.Col3

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top