Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4023568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:36:52+00:00 2026-05-20T10:36:52+00:00

I have a scenario where I would like to update multiple fields in multiple

  • 0

I have a scenario where I would like to update multiple fields in multiple Tables using just one instuction. I need a Syntax to perform such opperations on multiple Databases (Oracle and MSSQL).

At the moment I am stuck at the following statement from MSSQL:

update table1
set table1.value = 'foo'
from table1 t1 join table2 t2 on t1.id = t2.tab1_id
where t1.id = 1234

I would like to update a field in t2 aswell in the same statement.

Further I would like to perform the same Update(s) on Oracle.

EDIT:
Seems like I can not update multiple Tables in just one statement.

Is there a syntax that works for Oracle and MSSql when updating using a Join?

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:36:52+00:00Added an answer on May 20, 2026 at 10:36 am

    Seems like I can not update multiple
    Tables in just one statement.

    Is there a syntax that works for
    Oracle and MSSql when updating using a
    Join?

    I assume when you re-posed the question you want syntax that will work on both Oracle and SQL Server even though it will inevitably affect only one table.

    Entry level SQL-92 Standard code is supported by both platforms, therefore the following ‘scalar subqueries’ SQL-92 code should work:

    UPDATE table1 
       SET my_value = (
                       SELECT t2.tab1_id
                         FROM table2 AS t2 
                        WHERE t2.tab1_id = table1.id
                      )       
     WHERE id = 1234
           AND EXISTS (
                       SELECT * 
                         FROM table2 AS t2 
                        WHERE t2.tab1_id = table1.id
                      );
    

    Note that while using the correlation name t1 for Ttble1 is valid syntax according to the SQL-92 Standard this will materialize a table and the UPDATE will then target the materialized table ‘t1’ and leave your base table ‘table1` unaffected, which I assume is not the desired affect. While I’m fairly sure both Oracle and SQL Server are non-compliant is this regard and that in practise would work as expected, there’s no harm in being ultra cautious and sticking to the SQL-92 syntax by fully qualifying the target table.

    Folk tend not to like the ‘repeated’ code in the above subqueries (even though the optimizer should be smart enough to evaluate it only once).

    More recent versions of Oracle and SQL Server support both support Standard SQL:2003 MERGE syntax, would may be able to use something close to this:

    MERGE INTO table1 
       USING (
              SELECT t2.tab1_id
                FROM table2 AS t2
             ) AS source
          ON id = source.tab1_id
             AND id = 1234
    WHEN MATCHED THEN
       UPDATE
          SET my_value = source.tab1_id;
    

    I just noticed your example is even simpler than I first thought and merely requires a simple subquery that should run on most SQL products e.g.

    UPDATE table1
       SET my_value = 'foo'
     WHERE EXISTS (
                   SELECT * 
                     FROM table2 AS t2 
                    WHERE t2.tab1_id = table1.id
                  );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scenario where I have multiple versions of the same assembly that
We have a custom PHP/MySQL CMS running on Linux/Apache thats rolled out to multiple
I have an application that allows different users to update some data that is
I have a view which is composed of top, left and bottom headers and
I have a question regarding DDD and the repository pattern. Say I have a
UPDATE: I recently learned from this question that in the entire discussion below, I
SOME CONTEXT one of my projects requires carrying around some of metadata (yes I
What is the best approach to synchronizing a DataSet with data in a database?
I hope this is a simple enough question for any SQL people out there...
Edit: When I say SQL Server, I'm really talking about the Management Studio. Sorry

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.