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 orm in sql?

725


What do you understand by exception handling in pl/sql?

762


Write the order of precedence for validation of a column in a table? I. Done using database triggers. Ii. Done using integarity constraints

848


how to get help information from the server? : Sql dba

681


What is 19 null in sql?

703






How to write a query to show the details of a student from students table whose

759


What is package in pl sql with an examples?

737


How many functions are there in sql?

724


What is a heap in sql?

723


How can you view the errors encountered in a trigger?

739


How can get second highest salary in sql?

693


What is case function?

780


Which data dictionary views have the information on the triggers that are available in the database?

946


How do you concatenate in sql?

725


How many triggers can be applied to a table?

784