Tuesday, October 11, 2016

SQL UNION

SQL UNION is used for two or more select statement without returning the any duplicates rows.
For UNION there need to same number of column and data type need to be same also select statement 
in a same order must. UNION usually returns distinct value.

Table 

A1
France
japan
France
India
Bangladesh

A2
France
japan
France
India
Canada

Query:

SELECT Employee FROM A1
UNION
SELECT Employee FROM A2
ORDER BY Employee;


Result:


Employee
France
japan
India
Bangladesh
Canada


SQL UNION ALL is used for two or more select statement with returning duplicates rows.

Query:

SELECT Employee FROM A1
UNION ALL
SELECT Employee FROM A2
ORDER BY Employee;







No comments:

Post a Comment