IT Community - Software Programming, Web Development and Technical Support

UNION ALL faster than a UNION?

This is a discussion on UNION ALL faster than a UNION? within the Database Support forums, part of the Web Development category; Why is a UNION ALL faster than a UNION?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-16-2007, 11:35 PM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Question UNION ALL faster than a UNION?

Why is a UNION ALL faster than a UNION?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-17-2007, 12:22 AM
prasath prasath is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: Chennai
Posts: 173
prasath is on a distinguished road
Default Re: Why is a UNION ALL faster than a UNION?

UNION ALL doesnot worry about duplicate records,but UNION consider the duplicate records or eliminate duplicate records.UNION ALL display all the records.UNION display the distinct records.so that UNION ALL is faster than
UNION

Here,we come to one conclusion,UNION achive the DATA REDUNANCY

Thanks
Prasath.K
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-07-2007, 07:58 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Default Re: Why is a UNION ALL faster than a UNION?

Hi there,

UNION : eliminates duplicates
UNION ALL: retains duplicates

Suppose I have five SQL SELECT statements connected by UNION/UNION ALL, how many times should I specify UNION to eliminate the duplicate rows?
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-18-2007, 12:57 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Wink Re: Why is a UNION ALL faster than a UNION?

The union operation, you will recall, brings two sets of data together. It will *NOT* however produce duplicate or redundant rows. To perform this feat of magic, a SORT operation is done on both tables. This is obviously computationally intensive, and uses significant memory as well.

A UNION ALL conversely just dumps collection of both sets together in random order, not worrying about duplicates.
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-18-2007, 02:04 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: Why is a UNION ALL faster than a UNION?

Quote:
Originally Posted by vadivelanvaidyanathan View Post
Why is a UNION ALL faster than a UNION?
UNION ALL will be faster b'coz UNION looks for the duplicate values and eliminates it where as UNION ALL will list all.
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/database-support/1879-union-all-faster-than-union.html
Posted By For Type Date
DiscussWeb IT Community - Technical Support and Technology Discussions This thread Refback 08-18-2007 02:44 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Make out of Structure and Union velhari C and C++ Programming 2 04-03-2008 03:55 AM
Union and Union All itbarota Database Support 2 03-03-2008 01:41 AM
What is the difference between UNION and UNIONALL in SQL Server? bluesky Database Support 1 07-25-2007 05:53 AM
what is the UNION in c++? with Example sundarraja C and C++ Programming 1 07-20-2007 07:44 AM
What's the difference between a structure and a union prasath C and C++ Programming 1 07-18-2007 05:14 AM


All times are GMT -7. The time now is 06:27 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0