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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:13:14+00:00 2026-05-24T20:13:14+00:00

I want to fill a table with data that might be overlapping. I do

  • 0

I want to fill a table with data that might be overlapping. I do this a few times in the code. so, the first time it is

INSERT INTO A (SELECT * FROM B)

and then the second time it is

INSERT INTO A
SELECT * FROM C
WHERE NOT EXISTS (SELECT * FROM A Where A.field = C.field)

the re-insertion is done a total of 3 times. I could change the code to just one insertion using a UNION on the 4 sub-tables, but it will require alot of re-design, so I wanted to know how much performance penalty I am receving right now

Thanks!!

  • 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-24T20:13:15+00:00Added an answer on May 24, 2026 at 8:13 pm

    A union is probably less costly. But as usual with databases, it depends.

    Why?

    Because what you are doing right now is this:

    1. Scan table B and insert into A.
    2. Scan table C and insert into A (where not exists).
    3. Scan table D and insert into A (where not exists).

    With a union you would be doing this:

    1. Scan table B.
    2. Scan table C.
    3. Scan table D.
    4. Insert unique values to table A.

    I.e. your current queries scans table B, C, D and table A twice plus overhead for three separate queries. A union-query would scan table B, C, D, and sort the rows (to get unique values) and then insert them into table A. At a first glance it seems that union would be faster because you are doing two less scans and only one insert (and thus less locking).

    What I mean by it depends is:

    Indexes: Correctly indexed, seeks might be faster than sorting the data from B, C and D.

    Amount of data: If you have little data compared to the hardware you are running the database on then this discussion might be pointless. I.e. there’s no point in optimizing parts that are not bottlenecks.

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

Sidebar

Related Questions

I am using JSON for first time... and want to fill my datagrid with
I have few tables that gather data for internal use but i want to
In a nutshell: I have some database table data that I want to populate
I want to fill an array in javascript that takes all the values out
I Had Drop down list and I want to fill it with data from
I have a for loop. Inside that loop I want to fill up an
Okay all, I have a form that I want users to fill out. When
I have done a table in SVG, and I want to fill it with
In page_load, I create a table and fill it with data gathered from a
I need to fill a UITableView from an NSSet data source. Obviously I want

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.