---
title: "DB2: How to Use Set Operators Example SQL"
description: "Here are example SQL queries explained on how to use Set Operators with multiple Tables"
url: https://srinimf.com/2017/12/13/db2-set-operators-to-never-miss-these/
date: 2017-12-13
modified: 2021-04-18
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2017/12/pexels-photo-6707628.jpeg?fit=1880%2C1253&ssl=1
categories: ["DB2", "SQL"]
tags: ["DB2 Set Operators"]
type: post
lang: en
---

# DB2: How to Use Set Operators Example SQL

Guys welcome to DB2 SQL. There are mostly used popular set operators. These set operators you always need to keep handy especially on how to use in your SQL while writing Queries for your project.

## Set Operators

1. Union
2. Union all
3. Except
4. Minus
5. Intersect

And how to use multiple operators is also you need to learn. In my [previous post](https://srinimf.com/2015/02/02/db2-set-operators/) I have explained the real use of these operators.

Before going in detail about all operators, I am giving here some good comparison on [UNION Vs UNION ALL](http://www.sqlitetutorial.net/sqlite-union/)

## **How to Use UNION**

The simple UNION is the same operator you had in high school set theory; it returns the rows that appear in either or both tables and removes redundant duplicates from the result table.

```
(SELECT a1 FROM S1
 UNION
 SELECT a2 FROM S2);
```

## **How to Use UNION All**

The UNION ALL preserves the duplicates from both tables in the result table.

```
(SELECT a1 FROM S1
 UNION ALL
 SELECT a2 FROM S2)
```

Keep Reading

[![Understanding SQL Set Operators: UNION, INTERSECT, MINUS](https://i0.wp.com/srinimf.com/wp-content/uploads/2021/03/10-sql-set-operator-rules.png?fit=600%2C338&ssl=1)](https://srinimf.com/2021/03/21/10-top-sql-set-operator-rules/)

### [Understanding SQL Set Operators: UNION, INTERSECT, MINUS](https://srinimf.com/2021/03/21/10-top-sql-set-operator-rules/)

[![Srini&apos;s avatar](https://secure.gravatar.com/avatar/f10b4bafeeb96dce9806c5a3c6cde6ea1e2c014ef273120a4bf2c6d5f975f01c?s=48&r=g)](https://srinimf.com/author/moonrobot/)
by [Srini](https://srinimf.com/author/moonrobot/)
March 21, 2021

[![DB2: How to Use Set Operators Example SQL](https://i0.wp.com/srinimf.com/wp-content/uploads/2017/12/pexels-photo-6707628.jpeg?fit=600%2C400&ssl=1)](https://srinimf.com/2017/12/13/db2-set-operators-to-never-miss-these/)

### [DB2: How to Use Set Operators Example SQL](https://srinimf.com/2017/12/13/db2-set-operators-to-never-miss-these/)

[![Srini&apos;s avatar](https://secure.gravatar.com/avatar/f10b4bafeeb96dce9806c5a3c6cde6ea1e2c014ef273120a4bf2c6d5f975f01c?s=48&r=g)](https://srinimf.com/author/moonrobot/)
by [Srini](https://srinimf.com/author/moonrobot/)
December 13, 2017

[![6 DB2 SQL Set Operators](https://i0.wp.com/srinimf.com/wp-content/uploads/2015/02/pexels-photo-4226792.jpeg?fit=600%2C400&ssl=1)](https://srinimf.com/2015/02/02/db2-set-operators/)

### [6 DB2 SQL Set Operators](https://srinimf.com/2015/02/02/db2-set-operators/)

[![Srini&apos;s avatar](https://secure.gravatar.com/avatar/f10b4bafeeb96dce9806c5a3c6cde6ea1e2c014ef273120a4bf2c6d5f975f01c?s=48&r=g)](https://srinimf.com/author/moonrobot/)
by [Srini](https://srinimf.com/author/moonrobot/)
February 2, 2015

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2017%2F12%2F13%2Fdb2-set-operators-to-never-miss-these%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2017%2F12%2Fpexels-photo-6707628.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=DB2%3A%20How%20to%20Use%20Set%20Operators%20Example%20SQL)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2017/12/13/db2-set-operators-to-never-miss-these/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2017/12/13/db2-set-operators-to-never-miss-these/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2017/12/13/db2-set-operators-to-never-miss-these/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2017/12/13/db2-set-operators-to-never-miss-these/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20DB2%3A%20How%20to%20Use%20Set%20Operators%20Example%20SQL&body=https%3A%2F%2Fsrinimf.com%2F2017%2F12%2F13%2Fdb2-set-operators-to-never-miss-these%2F&share=email)
-

### Like this:

Like Loading…
