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!

Need help with "update query"

Status
Not open for further replies.

hoctro

Technical User
Mar 29, 2001
34
US
I have this sample problem where I want to update table test1 if the id in both tables match.


Problem (sample data):
========
Table "Test1"

id name
-- -------
1 "rrr"
2 "ttt"
4 "sss"

Table "Test 2"

id name
-- -------
1 "fff"
2 "ggg"
3 "hhh"

Expected Results:
Results:
Test1:

id name
-- ------
1 "fff"
2 "ggg"
4 "sss"



This query doesnt work. What is wrong with it ?
update Test1
set Test1.name = Test2.name
from Test1, Test2
where Test1.id = Test2.id


Much thanks,
Nga

 
Your query won't work because you are using a "from statement" in an update statement improperly.
Try this:

update Test1
set Test1.name = (select Test2.name
from Test2
where Test1.id = Test2.id)
This should work. Let me know. Hope this response didn't come too late.
chidi

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top