what is the difference between union and union all

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the the update statement in sql?

575


How do you modify a column in sql?

536


What is insert command in sql?

529


What is sql*loader and what is it used for? : aql loader

624


is it possible to pass an object or table to a procedure as an argument?

576






What is blind sql injection?

578


What is crud diagram?

515


How can use stored procedures in sql?

586


How would you reference column values before and after you have inserted and deleted triggers?

623


What is difference between joins and union?

535


Which type of cursor is used to execute the dml statement?

534


What are different types of statements supported by sql?

610


Difference between global and parameter variables?

1461


What is raw datatype in sql?

558


hi,i plan to put experience on PLSQL ,can anyone suggest me for any institutes in bangalore or how to prepare for interviews

1530