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

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.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close