what is the difference between union and union all

Answers were Sorted based on User's Feedback



what is the difference between union and union all..

Answer / soubhagya

Union:
It retrieves only distinct records.

Union all:
This retrieves duplicate records too.

but in performance issue
unioun all is better becoz it doesnot sort, filter the
record so its faster.

Is This Answer Correct ?    5 Yes 0 No

what is the difference between union and union all..

Answer / srinivas

Another difference is that union will sort the result sets
whereas union all will not.

Is This Answer Correct ?    4 Yes 1 No

what is the difference between union and union all..

Answer / vibha kant pandey

Hi friends check it this may help you all.

UNION
The UNION command is used to select related information from
two tables, much like the JOIN command. However, when using
the UNION command all selected columns need to be of the
same data type. With UNION, only distinct values are selected.

UNION ALL
The UNION ALL command is equal to the UNION command, except
that UNION ALL selects all values.

The difference between Union and Union all is that Union all
will not eliminate duplicate rows, instead it just pulls all
rows from all tables fitting your query specifics and
combines them into a table.

A UNION statement effectively does a SELECT DISTINCT on the
results set. If you know that all the records returned are
unique from your union, use UNION ALL instead, it gives
faster results.

Example :-
Table X contain values(a,b,c) and Table Y
contain values(c,d,e)
In Case Of Union we will get Result-a,b,c,d,e
and other hand (Union All ) we will get-a,b,c,c,d,e.

Is This Answer Correct ?    3 Yes 1 No

what is the difference between union and union all..

Answer / leena

union all will combine the outputs of two or more queries.
union will combine the outputs of two or more queries but remove or ignore duplicate value in output.
union all is most faster as compare to union

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

Why is nosql good?

0 Answers  


What is the use of <> sql?

0 Answers  


Which is better join or inner query?

0 Answers  


What are the PL/SQL Statements used in cursor processing ?

4 Answers  


SELECT emp_num, years, SUM(salary) FROM sales UNION ALL SELECT emp_id, SUM(takehomepay) FROM marketing What error is present in the sample code above? 1. Queries being combined with the UNION ALL statement are not allowed to have SELECT lists with a different number of expressions. 2. You are not allowed to use aggregate functions within two queries joined by a UNION ALL statement. 3. The UNION ALL statement incorrectly combines the "years" result from the first query with the "SUM (takehomepay)" result from the second query. 4. Unless the UNION ALL statement is replaced with a UNION statement, the queries will return duplicates. 5. The "emp_id" column from the second query must be renamed (or aliased) as "emp_num" so that it corresponds to the column name from the first query. Otherwise, the queries will not execute.

3 Answers  






How many types of functions are there in sql?

0 Answers  


How do you remove duplicates without using distinct in sql?

0 Answers  


What is scope of pl sql developer in future?

0 Answers  


I want to know the difference between A Record Type and a Table.

3 Answers   Thermotech,


Can you skip header records while loading? : aql loader

0 Answers  


Is t sql a programming language?

0 Answers  


Why are sql stored procedures used?

0 Answers  


Categories