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


Dig Deeper on Oracle and SQL

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