Q

Updating a table by adding data from another table

Can I update a table by adding data from another table?

TABLE1 s_ID, s_name, ownerID
120   NAME    <<data here>>
TABLE2
ownerID, s_name
650      NAME NAME
I want to get the (new table association) TABLE1.ownerID rows populated with the values from TABLE2.ownerID. I need somthing like:
update TABLE1
set ownerID = table2.ownerID
where table1.s_name + ' String' = table2.s_name
I'm using SQL Server 7.0 AND SQL Server 2000.


Here, I would use a simple correlated sub-query.

update TABLE1
  set OwnerID = ( select OwnerID from TABLE2 
                    where s_name = table1.s_name + 
                                   'String');
For more information, you can see the responses I posted to similar questions at http://searchdatabase.techtarget.com/ateAnswers/0,289620,sid13_cid412523_tax289340,00.html.

For More Information


This was last published in September 2002

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close