Problem: How to combine results
from two or more queries.
Combines
the results of two or more queries into a single result set that includes all
the rows that belong to all queries in the union. The UNION operation is
different from using joins that combine columns from two tables.
The following are basic rules for combining the result sets of
two queries by using UNION:
·
The number and the order of the columns must be the same in all
queries.
·
The data types must be compatible.
Example:
In this
article I am going to show you how Union can be used and a few examples.
I Have an
employee table and I am filter the table by filtering on employee type and this
two give two separate results.
select *
from dbo.employees
where employeetype='tester'
select * from
dbo.employees where
employeetype='developer'
I am going
to combine these two results into a sing result using UNION.
select * from
dbo.employees where
employeetype='tester'
UNION
select * from
dbo.employees where
employeetype='developer'
OUTPUT:
0 comments:
Post a Comment