# Set Theory Operations in Relational Algebra

Prerequisite – Relational Algebra in DBMS
These Set Theory operations are the standard mathematical operations on set. These operations are Binary operation that is, these are operated on 2 relations unlike PROJECT, SELECT and RENAME operations. These operations are used to merge 2 sets in various ways.

The set operation are mainly categorized into the following:

1. Union operation
2. Intersection operation
3. Set difference or Minus operation

Before we apply one of the 3 set operations on relations, the two relations on which we are performing the operations must have same type of tuples. This is also known as be Union compatibility (or Type compatibility).

Type compatibility:
Two relations A(P1, P2, …, Pn) and B(Q1, Q2, …, Qn) are said to be Type compatible (or Union compatible) if both the relation have same degree ‘k’ and

`domain(Pi) = domain(Qi) for 1<= i <= k. `

1. UNION Operation:

Notation:

```A ∪ S
```

where, A and S are the relations,

symbol ‘∪’  is used to denote the Union operator.

The result of Union operation, which is denoted by A ∪ S, is a relation that basically includes all the tuples that are present in A or in S, or in both, eliminating the duplicate tuples.

Important points on UNION Operation:

1. The UNION operation is commutative, that is :

`A ∪ B = B ∪ A`

2. The UNION is associative, that means it is applicable to any number of relation.

`A ∪ ( B ∪ C ) = ( A ∪ B ) ∪ C`

3. In SQL, the operation UNION is as same as UNION operation here.

4. Moreover, In SQL there is multiset operation UNION ALL.

2. INTERSECTION Operation:

Notations:

```A ∩ S
```

where, A and S are the relations,

symbol ‘∩’  is used to denote the Intersection operator.

The result of Intersection operation, which is denoted by A ∩ S, is a relation that basically includes all the tuples that are present in both A an S.

Important points on INTERSECTION Operation:

1. The INTERSECTION operation is commutative, that is :

`A ∩ B = B ∩ A`

2. The INTERSECTION is associative, that means it is applicable to any number of relation.

`A ∩ ( B ∩ C ) = ( A ∩ B ) ∩ C`

3. INTERSECTION can be formed using UNION and MINUS as follows:

`A ∩ B = ((A ∪ B) - (A - B)) - (B - A)`

4. In SQL, the operation INTERSECT is as same as INTERSECTION operation here.

5. Moreover, In SQL there is multiset operation INTERSECT ALL.

3. MINUS (or SET DIFFERENCE) Operation:

Notations:

```A - S
```

where, A and S are the relations,

symbol ‘ – ’  is used to denote the Minus operator.

The result of Intersection operation, which is denoted by A – S, is a relation that basically includes all the tuples that are present in A but not in S.

Important points on MINUS (or SET DIFFERENCE) Operation:

1. The SET DIFFERENCE operation is not commutative, that means :

`A - B != B - A`

2. In SQL, the operation EXCEPT is as same as MINUS operation here.

3. Moreover, In SQL there is multiset operation EXCEPT ALL.

Example:
Consider a relation Student(FIRST, LAST) and Faculty(FIRSTN, LASTN) given below :

First Last
Aisha Arora
Bikash Dutta
Makku Singh
Raju Chopra

FirstN LastN
Raj Kumar
Honey Chand
Makku Singh
Karan Rao

1. Student UNION Faculty :

`Student ∪ Faculty `

First Last
Aisha Arora
Bikash Dutta
Makku Singh
Raju Chopra
Raj Kumar
Honey Chand
Karan Rao

2. Student INTERSECTION Faculty :

`Student ∩ Faculty `

First Last
Makku Singh

3. Student MINUS Faculty :

`Student - Faculty`

First Last
Aisha Arora
Bikash Dutta
Raju Chopra
Raj Kumar
Honey Chand
Karan Rao

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.