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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:31:40+00:00 2026-06-15T16:31:40+00:00

I am running into some performance issue and I have a query as follow:

  • 0

I am running into some performance issue and I have a query as follow:

SELECT * FROM Foo

UNION

SELECT * FROM Boo

UNION

SELECT * FROM Koo

I know for sure that Koo is not returning any duplicates. I was considering to use UNION ALL at the end and therefore save the sorting and distinct selection time for Koo. The query should look like:

SELECT * FROM Foo

UNION

SELECT * FROM Boo

UNION ALL

SELECT * FROM Koo

Will that help or it will be affected bu the first UNION?

  • 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-15T16:31:41+00:00Added an answer on June 15, 2026 at 4:31 pm

    Always use UNION ALL if you know that there will not be duplicates.

    It’s a bit gray here, but still worthwhile – although practically marginal.

    If it’s a straight UNION-UNION, SQL Server can optimize this to collate all 3 result sets and perform a single sort across both. Since sorting is mostly O(n log n), it amounts to very little difference between that and [(A distinct B) add C].

    update

    Although it is possible to perform a single merge-sort, SQL Server doesn’t seem to do it (at least not always) – so the wisdom of using UNION ALL is definitely worth it here. Compare the plans here: SQLFiddle (click on the “View Execution Plan” links)

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

Sidebar

Related Questions

I am running into some difficulty with the following query. SELECT maker, speed FROM
I am running into some performance issue with php and mysql page. i have
We're running into transaction issue with Grails. During performance test we have a scenario,
I have been trying to learn Erlang and have been running into some problems
I'm using Perl to perform some file cleansing, and am running into some performance
I've been working with Google App Engine and I'm running into some slow performance
I'm running into a strange issue on Vista with the Performance monitoring API. I'm
I running into some performance issues with a jquery script I wrote when running
I'm running into some positioning inconsistencies between browsers. I'm trying to position a submit
I'm running into some problems using my .NET 4.0 libraries in .NET 2.0 applications.

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.