There are many set operations in practice, but in this segment, you will learn about union, intersection and difference. A set is a collection of distinct values. It is denoted by comma-separated values enclosed by curly braces.
Consider two sets A and B containing even numbers and prime numbers, respectively. For ease of understanding, let’s consider only values less than 10. Therefore, the sets will be A = { 2, 4, 6, 8} and B = { 2, 3, 5, 7 }.
The union of A and B (denoted by A ∪ B) will contain all the values that are present in either A or B. Therefore, A ∪ B = { 2, 3, 4, 5, 6, 7, 8 }.
The intersection of A and B (also denoted by A ∩ B) will contain all the values that are present in both A and B. Therefore, A ∩ B = { 2 }.
The set difference of A and B (also denoted by A – B) will contain all the values that are present in A but not in B. Therefore, A – B = { 4, 6, 8 }.
You have understood some basic concepts of Sets and now in the next segment, you will learn about the different types of Joins.