Reputation: 139
Given a relation A(a,b,c), and a relation B(a,d,e), using projection to isolate 'a' in 'B' like so 'B_=projection_{a}(B)', is there a way to exclude all tupples in 'A', that does not have an 'a' in common with 'B'?
Note that i'm only using relational algebra, and not the extended version.
Upvotes: 0
Views: 69
Reputation: 2806
is there a way to exclude all tupples in 'A', that does not have an 'a' in common with 'B'?
That's a double negative: "exclude ... not ...". Let's turn it into a positive:
"Show all tuples in A
that do have an a
in common with B
."
That is, you want a subset of the tuples. It's important here that a
is the only attribute name in common between the two relations. Then here's a start with Natural Join.
A ⋈ B
That will produce a result with all attributes {a, b, c, d, e}
. Not yet what you want, so you're on the right track with a projection. I'll use Codd's original operator (π
). There's two ways; these are equivalent:
A ⋈ (π{a}( B )) // take just {a} from B
π{a, b, c}( A ⋈ B ) // take {a, b, c} from the result of Join
It's a commonly-needed operation, so there's also a shorthand amongst the "extended" set of operators, to avoid that projection, called (left) SemiJoin
A ⋉ B
Also called 'Matching'.
Upvotes: 2