what is the difference between UNION AND UNIONALL

Answers were Sorted based on User's Feedback



what is the difference between UNION AND UNIONALL..

Answer / k

UNION provides only distinct values as output whereas UNION
ALL provides all values.
So UNION ALL seems to be faster than UNION.

Is This Answer Correct ?    25 Yes 1 No

what is the difference between UNION AND UNIONALL..

Answer / vinod singh kushwah

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.

Note: With UNION, only distinct values are selected.

SQL Statement 1
UNION
SQL Statement 2

Employees_Norway:

E_ID E_Name
01 Hansen, Ola
02 Svendson, Tove
03 Svendson, Stephen
04 Pettersen, Kari

Employees_USA:

E_ID E_Name
01 Turner, Sally
02 Kent, Clark
03 Svendson, Stephen
04 Scott, Stephen


------------------------------------------------------------
--------------------

Using the UNION Command
Example
List all different employee names in Norway and USA:

SELECT E_Name FROM Employees_Norway
UNION
SELECT E_Name FROM Employees_USA

Result

E_Name
Hansen, Ola
Svendson, Tove
Svendson, Stephen
Pettersen, Kari
Turner, Sally
Kent, Clark
Scott, Stephen

Note: This command cannot be used to list all employees in
Norway and USA. In the example above we have two employees
with equal names, and only one of them is listed. The UNION
command only selects distinct values.


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

SQL Statement 1
UNION ALL
SQL Statement 2


------------------------------------------------------------
--------------------

Using the UNION ALL Command
Example
List all employees in Norway and USA:

SELECT E_Name FROM Employees_Norway
UNION ALL
SELECT E_Name FROM Employees_USA

Result

E_Name
Hansen, Ola
Svendson, Tove
Svendson, Stephen
Pettersen, Kari
Turner, Sally
Kent, Clark
Svendson, Stephen
Scott, Stephen

Is This Answer Correct ?    20 Yes 0 No

what is the difference between UNION AND UNIONALL..

Answer / vaithianathan

union displays only different values in the multiple table.
but union all displays all related values.

Is This Answer Correct ?    1 Yes 0 No

what is the difference between UNION AND UNIONALL..

Answer / krishna kant kumar

The UNION operator returns all rows from two or multiple tables and eliminates any duplicate rows but the UNION ALL operator returns from both queries, including all duplications.
The UNION operator can use DISTINCT keyword but the UNION ALL cannot it.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Oracle General Interview Questions

What are the ansi data types supported in oracle?

0 Answers  


23. Display the client name for all clients who have placed an order where any order line has more than 3 items. Do not use a table join anywhere in your query.

3 Answers   Wipro,


What are transaction isolation levels supported by oracle?

0 Answers  


What is backup in Oracle?

0 Answers   MCN Solutions,


how to get required data from oracle source is like this ram_05_seetha lax_05_viswa bamr05frummy run_01_away sw_sas_trim i want my target data like ram_05_seetha lax_05_viswa to get data using %_05_% but it will give ram_05_seetha lax_05_viswa bamr05frummy how can i get my target data?

1 Answers   Infosys,






What do you understand by a database object?

0 Answers  


Why oracle is used?

0 Answers  


what are the things that you consider while creating indexes on partitioning tables?

1 Answers  


When a form is invoked with call_form, Does oracle forms issues a save point ?

1 Answers   Oracle,


how to code performance tuning of oracle PL/SQL? can any body send me the perfect answer?

1 Answers   IBM,


What is difference between UNIQUE constraint and PRIMARY KEY constraint ?

3 Answers  


How to call a sub procedure?

0 Answers  


Categories
  • Oracle General Interview Questions Oracle General (1789)
  • Oracle DBA (Database Administration) Interview Questions Oracle DBA (Database Administration) (261)
  • Oracle Call Interface (OCI) Interview Questions Oracle Call Interface (OCI) (10)
  • Oracle Architecture Interview Questions Oracle Architecture (90)
  • Oracle Security Interview Questions Oracle Security (38)
  • Oracle Forms Reports Interview Questions Oracle Forms Reports (510)
  • Oracle Data Integrator (ODI) Interview Questions Oracle Data Integrator (ODI) (120)
  • Oracle ETL Interview Questions Oracle ETL (15)
  • Oracle RAC Interview Questions Oracle RAC (93)
  • Oracle D2K Interview Questions Oracle D2K (72)
  • Oracle AllOther Interview Questions Oracle AllOther (241)