sorry for writing value1 etc..field1 , field2 are columns from table Other
Update Test
set va1 = field1
, va2 = field2
from Other
where ........
Main Topics
Browse All TopicsIn SQL we can do the following
insert into Test(va1, va2, va3)
select va1, va2, va3
from Other
where ......
How do I do the same thing like above but in format of update-select ?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I find that using a joined table update is the easiest.
example:
Update Test Inner Join Other On
Test.TPK = Other.OPK
Set
Test.va1 = Other.va1,
Test.va2 = Other.va2,
Test.va3 = Other.va3
======================
You should also be able to do something like the following:
Update Test
Set
Test.va1 = (Select Other.va1 From
Other Where Test.TPK = Other.OPK)
Test.va2 = (Select Other.va2 From
Other Where Test.TPK = Other.OPK),
Test.va3 = (Select Other.va3 From
Other Where Test.TPK = Other.OPK)
Test1 table :
ID Item Text Number
-- ------ ----- ---------
1 101 111 1001
2 102 222 1002
3 103 333 1003
First, I will insert a row into this table with this data:
ID = 4
Number = 1001
Now Test1 is :
ID Item Text Number
-- ------ ----- ---------
1 101 111 1001
2 102 222 1002
3 103 333 1003
4 1001
Now, I want to do a update based on Number 1001,
so 101 and 111 will go to row's ID 4.
I just want to know how to use update-select to acheive this.
Update Test1 Inner Join Test1 As Other On
Test1.Number = Other.Number
Set
Other.[Item] = Test.[Item] ,
Other.[Text] = Test.[Text]
Where Test1.ID = (Select Min(T2.ID) From Test1 As T2 Where T2.Number = 1001)
And
Test1.ID < Other.ID
And
Other.ID = (Select Max(T3.ID) From Test1 As T3 Where T3.Number = 1001)
And
Other.[Item] Is Null
And
Other.[Text] Is Null
Business Accounts
Answer for Membership
by: pra_kumar03Posted on 2004-02-24 at 12:43:39ID: 10444529
Update Test
set va1 = value1
, va2 = value2
from Other
where ........