---
title: "When will union and union all behave the same?"  
description: "When will union and union all behave the same?"  
author: "Anonymous User"  
published: 2018-03-12  
updated: 2020-09-23  
canonical: https://www.mindstick.com/interview/23347/when-will-union-and-union-all-behave-the-same  
category: "database"  
tags: ["database", "sql server", "sql server 2008"]  
reading_time: 1 minute  

---

# When will union and union all behave the same?

Union will return record only once even if it occurs several times. Union all will give a record as many times as it occurs. So union and union all will behave the same when each record is distinct in all the participating tables.

eg

```
select name, id from Emp1 union select name, id from Emp2

select name, id from Emp1 union all select name, id from Emp2
```

## Answers

### Answer by Anonymous User

Union will return record only once even if it occurs several times. Union all will give a record as many times as it occurs. So union and union all will behave the same when each record is distinct in all the participating tables.

eg

```
select name, id from Emp1 union select name, id from Emp2

select name, id from Emp1 union all select name, id from Emp2
```


---

Original Source: https://www.mindstick.com/interview/23347/when-will-union-and-union-all-behave-the-same

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
