Result of a set difference operator in relational algebra
Question:
6. Which of the following is equivalent to the expression R - (R - S)?
(a) R
(b) S
(c) R - S
(d) R ∩ S
Answer:
(d) R ∩ S
R - (R - S) is equivalent to R ∩ S . This could be understood from the following example;
Let
us take the following tables (relations) R and S with 3 and 2 tuples
respectively.
R
|
||
B
|
D
|
|
Tuple
1
|
b1
|
d1
|
Tuple
2
|
b2
|
d2
|
Tuple
3
|
b3
|
d3
|
S
|
||
B
|
D
|
|
Tuple
1
|
b1
|
d4
|
Tuple
2
|
b3
|
d3
|
The
following table shows R-S. The result contains all the records that are unique
for R and not for S. In other words, the common tuple in R and S is removed and
the tuples that are only part of R is retained.
R
– S
|
||
B
|
D
|
|
Tuple
1
|
b1
|
d1
|
Tuple
2
|
b2
|
d2
|
The
following table shows R-(R-S). The result contains records that are unique for
R and not for (R-S).
R
– (R – S)
|
||
B
|
D
|
|
Tuple
1
|
b3
|
d3
|
From
the result, it is very clear that the tuple (b3, d3) is the common tuple that
presents in both R and S. Hence, R-(R-S) is equivalent to R ∩ S.
No comments:
Post a Comment