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


Please Help Members By Posting Answers For Below Questions

What is before and after trigger?

610


What is embedded sql with example?

645


Which constraints we can use while creating database in sql?

698


How do I remove sql plus from windows 10?

663


Why we use triggers in mysql?

640






what are the disadvantages of mysql? : Sql dba

658


what are aggregate and scalar functions? : Sql dba

653


- Types of triggers - View - Dcl - Procedures, packages, functions - Metasolve - Can use Dcl in triggers - package case study - Cursor and its types - triggers schedule - Wrap - Why we are using fetch and for in cursor. difference?

1484


What are the benefits of pl sql?

622


Write a sql query to get the third highest salary of an employee from employee_table?

737


What is the difference between row level and statement level trigger?

621


How global cursor can be declare with dynamic trigger ?

1850


How can check sql version from command line?

625


What is number function in sql?

612


Why do we need a foreign key?

655