[0:06]Hello everyone and welcome back. In the previous video, we learned about the unary relational algebra operations. Now, the next group of relational algebra operations are the standard operations that we perform on a set. So, in this video, we will be discussing about those operations, that is the relational algebra operations from set theory. In this video, we will be learning about the union operation, intersection operation, minus operation and the cartesian product. Now, for the three operations, that is the union, intersection and set difference or the minus operation, the two relations on which any of these three operations are applied must be union compatible or type compatible. Now, what is union compatibility? Two relations are said to be union compatible if they have the same degree or the same number of attributes and also if they have the same attribute domains. You will understand this better with the help of examples. Let us see the first type of relational algebra operation, the union operation denoted by R Union S. Where R and S are two relations. So, if I have two relations, relation R and relation S, then a union of these two relations would be a relation that includes all tuples that are either in R or in S or in both R and S. That is, the resulting relation would have tuples that are present only in R or only in S or even in both R and S. Here the duplicate tuples will be eliminated. Let us see an example. Here I'm taking a relation student with attributes FN or first name and LN or last name. Let me represent this relation as R. Also let me take another relation instructor with attributes F Name and L Name. I'm representing instructor as relation S. Here I'm representing the relations as R and S so that you will understand this definition better. Now, if I want to do a union of these two relations, first I have to check if it is union compatible. Now as I mentioned earlier, two relations are set to be union compatible if they have the same degree or if they have the same number of attributes. So this relation student is of degree two, that is it has two attributes and this relation instructor is also of degree two. Also, we need to check if the attribute domains are the same. That is, the attribute FN in the student relation should be of the same domain as this attribute F name in the instructor relation. Similarly, the attribute LN in the student relation should have the same domain as the attribute L name in the instructor relation. Since these two relations satisfies the two conditions that is they have the same degree as well as the attribute domains of both the relations are the same. So, therefore, these two relations are set to be union compatible. Now, I can perform a union operation on these two relations. Therefore, student union instructor or R Union S would give this resulting relation. This would be my resulting relation with tuples from both R and S. And if any duplicate tuples are there, they will be eliminated. So, from R, we have all the four tuples that is selected and from S, we have only one tuple that is selected. Since these two tuples are also present in R and already displayed in the result, we won't display these two tuples as duplicate tuples will be eliminated or duplicate tuples are not allowed. And that is all about the union operation. Now moving on to the next type of operation, the intersection operation denoted as R intersection S. Now an intersection of these two relations R and S would give me a result that would be a relation that includes all the tuples that are in both R and S. That is, the tuples that exist in both the relations or that are common to both the relations. Let us see an example. Here I'm taking the same set of relations, the student relation and the instructor relation. Since we have already seen that they are union compatible, let us see what would be the result of student intersection instructor or R intersection S. Now, the first tuple in the student relation will be compared with all the tuples from the instructor relation. As we know from the definition, the tuples that are present in R should also be present in S. Since this tuple is not present in the instructor relation, it won't be displayed. Now let us see the second tuple, Amy Jones. Since this tuple is also present in the instructor relation, it will be displayed. Now moving on to the third tuple, again that tuple is also present in the instructor relation, so that will be displayed. Now, the last tuple, Ernest Gilbert is not present in the instructor relation, so it will not be displayed. Hence, this would be our resulting relation of R intersection S with tuples that are present in both the relations. Again, here the duplicate tuples are eliminated. And that is all about the intersection operation. The next standard set operation is the minus operation or the set difference operation denoted as R minus S. Now R minus S or a set difference of these two relations would give a result that is a relation that includes all the tuples that are in R but not in S. Let us understand this better with the help of an example. Again, here I'm taking the same set of relations, the student relation and the instructor relation which I'm representing it as R and S. We already know that these two relations are union compatible. So let us see what would be the result of student minus instructor or R minus S. Let me take the first tuple from R. As per the definition, R minus S would give a result that is a relation that has all the tuples that are present only in R, but they are not present in S. Since this tuple is present only in R and not in S, it will be displayed in the resulting relation. Similarly, the second tuple is not only present in R, it is also present in S. Therefore that tuple will not be displayed. Moving on to the third tuple, again it is also present in S. Therefore, that tuple will not be displayed. The fourth tuple from relation R is only present in R and not in S. Therefore, that tuple will also be displayed. Hence, this would be our resulting relation of R minus S with tuples that are only present in R but not in S. Now let us also see what would be the result if I do S minus R. Then we know that it will give a result that is a relation which includes all the tuples that are present only in S but not in R. Let us see how that works. Let me take the first tuple from the relation S. Since this tuple is also present in relation R, it will not be displayed. Moving on to the second tuple, it is only present in relation S. Therefore that tuple will be displayed in the resulting relation. Now the third tuple from relation S is not only present here, but it is also present in the relation R. So, it will not be displayed. Therefore this would be a resulting relation of S minus R with tuples that are present only in S but not in R. Hope you have understood how to perform the minus operation. Moving on to the last type of set theory operation in relational algebra, the Cartesian product operation or the cross product operation or the cross joint operation denoted as R cross S. Now the cartesian product or the cross product or the cross join of any two relations would result in a relation that would have the combined attributes of those two relations that we have joined. Let us see an example. If I take a relation R with attributes A and B and another relation S with attributes C, D and E, let us see what would be the result of the cross product of these two relations, that is R cross S. Here I've taken a random example to show you how this operation works. Now this would be the result of R cross S.
[8:52]Let us see step by step as to how we got this resulting relation. Now when we apply cartesian product on two relations, every tuple of the relation on the left side will pair up with all the tuples of the relation on the right side. That is, if I do R cross S, then every tuple from the relation R will pair up with all the tuples from relation S. Here, the first tuple from relation R will first pair up with this tuple and hence the first tuple in this resulting relation. Again, the same first tuple from R will pair up with the second tuple in the relation S and hence the second tuple in the resulting relation. Similarly, the second tuple from relation R will pair up with all the tuples from relation S. So first it will pair up with this tuple from the relation S, which gives the third tuple in the resulting relation. Again this tuple will also pair up with the second tuple from the S relation and hence we get the fourth tuple in this resulting relation. Similarly, the last tuple from our relation also pairs up with all the tuples from the S relation, therefore, resulting in these two tuples. Hope you have understood the Cartesian product where every tuple from the relation on the left side will pair up with all the tuples from the relation on the right. Now if relation R is of degree P and relation S is of degree N, then the final relation or the resulting relation will be of the degree P plus N. That is, the sum of both the degrees. So this relation R is of degree two since it has two attributes and this relation S is of degree three, since it has three attributes. So the degree of the result R cross S will be two plus three, that is five. Also, the cardinality of R is three in this example, that is, it has three rows or three tuples. And the cardinality of relation S is two, that is two tuples. Hence, the cardinality of the resulting relation R cross S will be three into two, which is six. So the resulting relation of R cross S will have six tuples or six rows. Hope you have understood the Cartesian product operation. Generally this operation is done when we want to join two tables or two relations. Also, these two relations need not be union compatible when cartesian product operation is applied on them. That is all about the cartesian product or the cross product operation. With this, we come to the end of this video. In this video, we have learned about the different set theory operations in relational algebra, that is the union operation, the intersection operation, the set difference or the minus operation, and the cartesian product operation. Hope you have understood them. Thank you.



