Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

UNION and UNION ALL explained

Union:

The SQL UNION clause/operator is used to combine the results of two or more SELECT statements.

SQL UNION clause/operator removes all duplicate rows and returns only distinct rows.

Syntax:

SELECT column1 [, column2 ] ..

FROM table1 [, table2 ]

[WHERE condition]

UNION

SELECT column1 [, column2 ]

FROM table1 [, table2 ]

[WHERE condition]

Example:

SELECT * FROM [UserData]

UNIO

SELECT * FROM [Employee]


Union All:

The UNION ALL clause/operator is used to combine the results of two or more select statements

Including duplicate rows/records.

Syntax:

SELECT column1 [, column2 ]

FROM table1 [, table2 ]

[WHERE condition]

UNION ALL

SELECT column1 [, column2 ]

FROM table1 [, table2 ]

[WHERE condition]

Example:

SELECT * FROM [UserData]

UNION ALL

SELECT * FROM Employee


 

difference between union and union all explained in :http://www.codechef4u.com/post/2015/04/06/difference-between-union-and-union-all

Invalid entry,please enter valid data.

Loading