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
Explain about various levels of constraint.
what are all types of user defined functions? : Sql dba
What are the advantages of sql? Explain
What is normalization in a database?
Which tcp/ip port does sql server run on? How can it be changed? : Sql dba
What is sql character function?
Can you join a table to itself?
what is cursor and its type, what is ref cursor write a syntax to pass ref cursor into procedure out fucntion and call the procedure
What is inner join in sql?
where are cookies actually stored on the hard disk? : Sql dba
what is the difference between a local and a global temporary table? : Sql dba
Why is sql better than hql?
Is left join same as join?
What is the purpose of design view?
What are analytic functions in sql?