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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a column according to a colum in a different table 1

Status
Not open for further replies.

Sashanan

Programmer
Jan 19, 2001
235
NL
I am trying to get column data from one table to another. For example:

DestTable

Column1 Column2
1 NULL
2 NULL
3 NULL

SourceTable
Column3 Column4
1 63
2 18
3 21

I'm trying to get the values in Column4 to Column2. I've tried a couple of Update queries but I haven't found the right one yet. I started with:

Update DestTable
Set Column2 = SourceTable.Column4
Where Column1 = SourceTable.Column3

This wasn't allowed as I hadn't selected SourceTable in the Update clause, but I'm not allowed to select more than one table there.

I then figured I'd need a subquery here, so I tried:

Update DestTable
Set Column2 = (Select Column4
From SourceTable, DestTable
Where Column1 = Column3)

This won't work either, as it returns multiple values to the Set clause.

I'm pretty much stumped now. Can someone help me to find the right query for the job?
"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
You're almost there! Try this

Update DestTable
Set Column2 = Column4
From SourceTable, DestTable
Where Column1 = Column3

Greg.
 
Worked like a charm. Thanks a lot!
"Much that I bound, I could not free. Much that I freed returned to me."
(Lee Wilson Dodd)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top