![]() |
VOOZH | about |
Set theory operations in relational algebra are based on basic mathematical set operations. Unlike commands like SELECT, PROJECT or RENAME (which work on a single table), these are binary operations, meaning they work on two relations (or tables) at a time. Theyβre mainly used to combine, compare or filter data between two sets in different ways. Whether you're merging tables, finding common entries or identifying differences, set operations give you the tools to do it efficiently and logically. The set operation is mainly categorized into the following:
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 the same degree 'k' and
domain(Pi) = domain(Qi) for 1<= i <= k.
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.
Example :
R = {(1, 'Alice'), (2, 'Bob')}
S = {(2, 'Bob'), (3, 'Charlie')}
R βͺ S = {(1, 'Alice'), (2, 'Bob'), (3, 'Charlie')}
Important points on UNION Operation:
A βͺ B = B βͺ A
A βͺ ( B βͺ C ) = ( A βͺ B ) βͺ C
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.
Example :
R = {(1, 'Alice'), (2, 'Bob')}
S = {(2, 'Bob'), (3, 'Charlie')}
R β© S = {(2, 'Bob')}
Important points on INTERSECTION Operation:
A β© B = B β© A
A β© ( B β© C ) = ( A β© B ) β© C
A β© B = ((A βͺ B) - (A - B)) - (B - A)
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.
Example :
R = {(1, 'Alice'), (2, 'Bob')}
S = {(2, 'Bob'), (3, 'Charlie')}
R β S = {(1, 'Alice')}
Important points on MINUS (or SET DIFFERENCE) Operation:
A - B != B - A
Consider a relation Student(FIRST, LAST) and Faculty(FIRSTN, LASTN) given below :
Table Student:
| First | Last |
|---|---|
| Aisha | Arora |
| Bikash | Dutta |
| Makku | Singh |
| Raju | Chopra |
Table Faculty:
| 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 |
For more information about more operations you can refer to - Set theory operations.