Wednesday, 30 March 2011

What is the difference between UNION and UNION ALL?

UNION selects only distinct values whereas UNION ALL selects all values and not just distinct ones.

----------------------------Union------------------------------------

SELECT column_names FROM table_name1
UNION
SELECT column_names FROM table_name2

-----------------------------Union All--------------------------------
SELECT column_names FROM table_name1
UNION ALL
SELECT column_names FROM table_name2

No comments:

Post a Comment