In: Computer Science
Consider the tables You may assume the corresponding columns have the same domains
T1
D | E | F |
10 | a | 5 |
15 | b | 8 |
15 | c | 4 |
25 | a | 6 |
T2
A | B | C |
10 | b | 6 |
25 | c | 3 |
10 | b | 5 |
Show the results of each of the following relational algebra expressions in terms of table:
i. T1 ⋈ (D = A) T2
ii. T1⋈ (E=B) T2
iii. T1∪T2
iv. T1–T2
v. π (D,E)(T1) / π (B) (T2)
T1 :
D | E | F |
10 | a | 5 |
15 | b | 8 |
15 | c | 4 |
25 | a | 6 |
T2:
A | B | C |
10 | b | 6 |
25 | c | 3 |
10 | b | 5 |
i)
This will return the rows in which column D and A have equal values
after doing the cross product
D | E | F | A | B | C |
10 | a | 5 | 10 | b | 6 |
10 | a | 5 | 10 | b | 5 |
25 | a | 6 | 25 | c | 3 |
ii)
This will return the rows in which column E and B have equal values
after doing the cross product.
D | E | F | A | B | C |
15 | b | 8 | 10 | b | 6 |
15 | b | 8 | 10 | b | 5 |
15 | c | 4 | 25 | c | 3 |
iii)
Append the rows of T2 after T1 to get the union of two tables
D | E | F |
10 | a | 5 |
15 | b | 8 |
15 | c | 4 |
25 | a | 6 |
10 | b | 6 |
25 | c | 3 |
10 | b | 5 |
iv)
Subtract the rows from T1 that are same in T2
There are no similar rows in both the tables. So T1 - T2 is the
same as T1
D | E | F |
10 | a | 5 |
15 | b | 8 |
15 | c | 4 |
25 | a | 6 |
v)
In this express there are two terms.
We analyze them separately
gives columns D and E from T1
D | E |
10 | a |
15 | b |
15 | c |
25 | a |
gives column B from T2
B |
b |
c |
We have to divide these two tables. Dividing means giving those
values of T1(D) which are occurring with every value of T2(B) in
T1
In T1, 10 occurs with a not with b and c.
15 occurs with both b and c. So it will be in the output
25 occurs with a.
So, the output of the given expression will be
D |
15 |
Hope this helps
If you have any doubt feel free to comment
Thank You!!