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

  • Home
  • SEARCH
  • 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 8120125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:01:26+00:00 2026-06-06T05:01:26+00:00

Suppose I have two tables Main and Other like the following: Main +———-+———————————–+ |

  • 0

Suppose I have two tables Main and Other like the following:

                    Main
+----------+-----------------------------------+
|  Field1  |  <set of other columns...>        |
+----------+-----------------------------------+
|   NULL   |           ...                     |
|   NULL   |           ...                     |
|   NULL   |           ...                     |


                          Other
           +-----------------------------------+
           |  <same set of other columns...>   |
           +-----------------------------------+
           |           ...                     |
           |           ...                     |
           |           ...                     |

Is there a concise way to update Main.Field1 where the rest of the columns, taken together, are not in a row of Other?

In other words, I want to update Field1 for each row in

SELECT <set of other columns...> FROM Main
   EXCEPT
SELECT <same set of other columns...> FROM Other

Dynamic SQL is an option, but I’m trying to figure out the most efficient way to do something like this.

  • 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-06-06T05:01:28+00:00Added an answer on June 6, 2026 at 5:01 am

    If you really wanted to you could use the Except clause

    UPDATE m
    SET field = 'AValue'
    FROM 
       MAIN  m
       INNER JOIN 
        (SELECT * FROM MAIN
        EXCEPT
        SELECT * FROM OTHER ) t
    on m.PK = t.PK
    

    DEMO

    You should note that the use of * here is very fragile and you should explicitly set your field list. It also assumes that the joining fields (PK) are available in both Main and Other and they would be the same

    Other wise you’re much better off using NOT EXISTS or an ANTI-JOIN (LEFT/ISNULL)

    UPDATE m
       SET Field1 = 'foo'
    FROM 
       Main m
       LEFT JOIN 
         Other o
        ON m.FIELD2 = o.FIELD2
        AND m.FIELD3 = o.FIELD3
    WHERE 
       o.PK is null
    

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use SQL Server 2000. Suppose I have two tables like the following: Area
Suppose I have a table whose function is specifically to link two other tables
I have two tables suppose table 1 has two columns with short names and
Suppose we have a PostgreSQL database with two tables A, B. table A columns:
I want to get values from two tables like in the following example: Suppose
Suppose I have the following two tables in my MySQL database: Table 1:: EMP:
suppose i have two tables. articles and comments. when i am selecting columns from
Suppose I have two tables in SQL where table1 has columns - id, name,
Suppose I have two tables Table1 and Table2 with the following data. Column1 Column2
Suppose I have two tables, - emp(empId number(1),empName varchar2(50)) and - manager(manId number(5),managerName varchar2(100))

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.