1SELECT expression1, expression2, ... expression_n
2FROM tables
3[WHERE conditions]
4UNION ALL
5SELECT expression1, expression2, ... expression_n
6FROM tables
7[WHERE conditions];
1UNION ALL:
2COMBINES THE RESULT OF 2 QUERY AND
3DOESN'T REMOVE DUPLICATE ROWS
4AND DOESN'T SORT BY FIRST COLUMN
5
6UNION:
7COMBINES THE RESULT OF 2 QUERY AND
8REMOVES DUPLICATE ROWS AND
9SORTS BY FIRST COLUMN
1/* UNION AND UNION ALL*/
2union and union all operator in sql server are used to combine the result-set of
3two or more select queries.
4union remove duplicate rows, where as union all doesn't.
5.e.g_
6SELECT Column_List from Table_Name
7UNION
8SELECT Column_List from Table_Name
9/--------------------------------------------/
10.e.g_
11SELECT Column_List from Table_Name
12UNION ALL
13SELECT Column_List from Table_Name
14
15/* UNION AND JOIN */
16Union combine rows from 2 or more tables, where as
17join combine columns from 2 or more tables.
18
1UNION ALL:
2COMBINES THE RESULT OF 2 QUERY AND
3DOESN'T REMOVE DUPLICATE ROWS
4AND DOESN'T SORT BY FIRST COLUMN
5