what is the difference between union and union all
Answer Posted / vishal
UNION removes duplicates, whereas UNION ALL does not.
In order to remove duplicates the result set must be
sorted, and this may have an impact on the performance of
the UNION, depending on the volume of data being sorted,
and the settings of various RDBMS parameters ( For Oracle
PGA_AGGREGATE_TARGET with WORKAREA_SIZE_POLICY=AUTO or
SORT_AREA_SIZE and SOR_AREA_RETAINED_SIZE if
WORKAREA_SIZE_POLICY=MANUAL ).
Basically, the sort is faster if it can be carried out in
memory, but the same caveat about the volume of data
applies.
Of course, if you need data returned without duplicates
then you must use UNION, depending on the source of your
data.
I would have commented on the first post to qualify the "is
much less performant" comment, but have insufficient
reputation (points) to do so.
| Is This Answer Correct ? | 9 Yes | 1 No |
Post New Answer View All Answers
What is normalisation and its types?
what are the nonstandard string types? : Sql dba
What is the difference between instead of trigger and after trigger?
What is %rowtype in pl sql?
What does rownum mean in sql?
Is delete faster than truncate?
What is the location of pre_defined_functions.
Why is nosql good?
What are the different ddl commands in sql?
What is sql partition?
When do we use triggers?
How would you convert date into julian date format?
How do we use distinct statement? What is its use?
What are the different sql commands?
What is the difference between python and sql?