what is the difference between UNION AND UNIONALL
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
9)When information has to be stored w.r.t employees and their respective departments, which of the following is the Correct formulation of entries? A)Employee and department would together be represented as an entity. B)This is too less information to decide on entities. C)An employee would be one entity and a department would be another. D)Such a scenario cannot be modelled in RDBMS
What is the Extension of Oracle Database? As extension of Access Database is .mdb
How to delete a column in an existing table?
What is the oracle implicit cursor?
Is oracle a programming language?
There are three tables : E : EID,ENAME D : DID,DNAME empdept : eid, did select the employees who doesn't belong to any dep
What is open database communication (odbc) in oracle?
What is TNS File
What do you know about normalization? Explain in detail?
Can a Tablespace hold objects from different Schemes ?
How to recover a dropped index?
What happens to the current transaction if the session is ended?