logo-MindMajix
PostSQLSQL
J
Justus Blake

Posted on 21st June 2024|54 views

0
votes

What Is The Difference Between UNION And UNION ALL?

Please explain the difference between Union and Union ALL?

 

1 answers
Answers
P
Megha Sharma

Posted on 21st June 2024| views

Hey Justus,

The key difference between Union and Union ALL is that the Union eliminates duplicate records where all the columns in the results are the same whereas,  Union all does not eliminate duplicate records rather it selects the rows from all the tables that meet the condition of a specific query and combine into a result table.

Select Column1, Column2, Column3 from Table A
UNION
Select Column1, Column2, Column3 from Table B

For example: Consider two tables.

Table1:

Employee ID

EmpName

Work experience

1

Arjun

1

2

Chaitanya

3

3

David

2

4

Karthik

4

5

Priya

2.5

Table:2

Manager ID

ManagerName

Work experience

1

Abhi

5

2

David

4

3

Sameer

6

4

Priya

SELECT EmpName FROM Employee
UNION
SELECT ManagerName FROM Manager

No.

EmpName

1

Arjun

2

Abhi

3

Chaitanya

4

David

5

Karthik

6

Sameer

7

Priya

Union ALL is a command used to concatenate the records. It pulls the values from all the tables so it does not remove the duplicate records.

Select Column1, Column2, Column3 from Table A
UNION ALL
Select Column1, Column2, Column3 from Table B

No

EmpName

1

Arjun

2

Chaitanya

3

David

4

Karthik

5

Priya

6

Abhi

7

David

8

Sameer

9

Priya

 

As we can see the Union ALL command doesn’t remove the duplicate records.

Union and Union ALL are the SQL operators used to concatenate two or more result sets. 

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number