Q
Problem solve Get help with specific problems with your technologies, process and projects.

UPDATE one table based on a condition in another

Is it possible to update a field in one table depending on a condition of a field in another? If so how is this...

done?

Yes, but the exact syntax will depend on your particular database system.

For example, in SQL Server:

update table1
   set fldX = T2.fldY
  from table1 T1
inner
  join table2 T2
    on T1.keyfld = T2.keyfld
 where T2.fldZ = 'foo'

... whereas in Microsoft Access:

update table1
inner 
  join table2 
    on table1.keyfld = table2.keyfld
   set table1.fldX = table2.fldY
 where table2.fldZ = 'foo'

Just another example of different databases implementing the same thing in different ways.

For More Information


This was last published in November 2003

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