web analytics

UNION vs UNION ALL in SQL

Options

codeling 1599 - 6654
@2016-01-13 21:29:39

Both UNION and UNION ALL concatenate the result of two different SQLs. They differ in the way they handle duplicates.

  • UNION operator performs a DISTINCT on the result set, eliminating any duplicate rows.

  • UNION ALL operator does not remove duplicates, and it therefore faster than UNION.

SELECT column_name(s) FROM table_name1
UNION | UNION ALL
SELECT column_name(s) FROM table_name2

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com