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 990257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:55:12+00:00 2026-05-16T05:55:12+00:00

I have a Microsoft SQL database, where i am trying to insert some data.

  • 0

I have a Microsoft SQL database, where i am trying to insert some data. I have a unique key on 4 columns and i want to insert data from multiple tables into this table while checking the data to make sure it will not violate the uniqueness of the key. If i was doing this on a single column, i would do a NOT IN, like so..

INSERT TABLE_A (FLD_1)
    SELECT FLD_1
        FROM TBL_B
        INNER JOIN TBL_C
            ON TBL_B.FLD_1 = TBL_C.FLD_1
    WHERE TBL_B.FLD_1 NOT IN
        (
        SELECT TBL_A.FLD_1 FROM TBL_A
        )

Any thoughts?

  • 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-16T05:55:13+00:00Added an answer on May 16, 2026 at 5:55 am

    Use NOT EXISTS instead since you have to deal with multiple columns.

    http://www.techonthenet.com/sql/exists.php

    EDIT:

    Untested, but roughly it will be this:

    SELECT FLD_1
    FROM TBL_B
    INNER JOIN TBL_C  ON TBL_B.FLD_1 = TBL_C.FLD_1
    WHERE NOT EXISTS 
        (
        SELECT TBL_A.FLD_1 FROM TBL_A INNER JOIN TBL_B ON TBL_B.FLD1 = TBL_A.FLD1
        )
    

    For a multi-column check it would be roughly this:

    SELECT FLD_1, FLD_2, FLD_3, FLD_4)
    FROM TBL_B
    INNER JOIN TBL_C  ON TBL_B.FLD_1 = TBL_C.FLD_1
    WHERE NOT EXISTS 
        (
        SELECT TBL_A.FLD_1, TBL_A.FLD_2, TBL_A.FLD_3, TBL_A.FLD_4 
        FROM TBL_A 
        INNER JOIN TBL_B ON TBL_B.FLD1 = TBL_A.FLD1 AND 
                            TBL_B.FLD2 = TBL_A.FLD2 AND 
                            TBL_B.FLD3 = TBL_A.FLD3 AND 
                            TBL_B.FLD4 = TBL_A.FLD4 
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have database with multiple tables in Microsoft SQL Server with schema in tables
I have a Microsoft SQL Server 2008 query that returns data from three tables
I have a database file .mdf from MS SQL EXPRESS in folder: C:\Program Files\Microsoft
I have a Microsoft SQL server DB that imports some data which needs a
I have been trying to connect netbean service for database explorer with Microsoft SQL
Running sql server 2005 I have database A. I am trying to restore from
I have an existing database(myDatabse) that I created with Microsoft Sql Managenent studio and
In Microsoft SQL database, I have a table where every column have default values
I have some data in a old MSSQL 2000 db. I am trying to
I'm currently trying to create FULLTEXT indexes into my database (Microsoft SQL Server 2005).

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.