Difference between Union and Union All in SQL

Last Updated on Jul 31, 2023
Download As PDF
IMPORTANT LINKS

Union and Union All are two fundamental operators in SQL that are used to merge the results of multiple tables. This article aims to highlight the key differences between Union and Union All.

An Overview of Union

Union is an operator in SQL that is used to combine the results of two queries into a single set. This is achieved using the select statement. A unique feature of Union is its ability to eliminate duplicate rows from the result set.


An Overview of Union All

Unlike Union, Union All does not eliminate any rows. It combines all rows from the two tables, including duplicates.

Comparing Union and Union All
S.No. UNION UNION ALL
1. Union eliminates duplicate rows from the result set. Union All does not eliminate duplicate rows from the result set.
2. Union may perform slower due to the process of eliminating duplicate rows. Union All performs faster as it does not have to process duplicate rows.
3. Union is commonly used by SQL users. Union All is not as commonly used as Union.
4. Syntax:

SELECT column_list FROM table1

UNION

SELECT column_list FROM table2;

Syntax:

SELECT column_list FROM table1

UNION ALL

SELECT column_list FROM table2;

Keep learning and stay updated with the latest information on GATE Exam , GATE Eligibility Criteria , GATE 2024 , GATE Admit Card , GATE Application Form , GATE Syllabus , GATE Cutoff , GATE Previous Year Question Paper , and more.

More Articles for Key Differences

Frequently Asked Questions

In SQL server, Union is an operator used for combining two queries into a single result set. It prefers the select statement and can remove the duplicate rows from the tables.

Union All is an SQL operator used for removing all the rows from a group of two tables.

The main difference between Union and Union All is that Union has the ability to remove duplicate rows from the table while Union All cannot. Union's performance is slower due to the elimination of duplicate rows, whereas Union All's performance is faster as it does not eliminate duplicate values.

Test Series
404.4k Students
SBI PO Mock Test Series 2025 (Pre + Mains)
367 TOTAL TESTS | 13 Free Tests
  • 13 Full Test (Mains)
  • 70 GA/CA Pack
  • 12 Sectional Test (Mains)
  • 89 Chapter Test
  • 2 2025 Trend Based FTs
  • 28 Full Test (Prelims)
  • 45 Most Saved Qs
  • 15 Sectional Test (Prelims)
  • 24 Memory Based Paper
  • 46 Memory Based Sectional Test
  • 23 IBPS Recent Exam MBTs

Get Started
Report An Error