Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

The ALL clause can speed up UNION statements

Total Hit ( 2826)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


If you omit the ALL clause in an UNION statement, SQL Server must delete duplicate values, which in turn means that it has to sort the two sub-resultsets that have to be combined. Needless to say, this is a time-consuming operation.

In most cases, you decide whether to use the ALL clause depending on your application requirements, and therefore you have no choice. However, if you are 100% sure that the two sub-resultsets have no duplicate rows, you can sensibly speed up execution by adding an explicit ALL clause, as in:

Click here to copy the following block
SELECT Name, State FROM USCustomers
UNION ALL
SELECT Name, Country FROM AbroadCustomers



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.