Reputation: 154
I have the relation A1 = (id1, id2)
and the relation A2 = (id, id1, id2)
, where id, id1, id2 are attributes.
I want to find intersection - (A1.id1 = A2.id1 ^ A1.id2 = A2.id2) of A1
and A2
, but it is impossible in relation algebra because they have different schema.
I want to intersect them not losing the "id" data. (I can not simple project A2 over id1 and id2 and then intersect)
So could I apply theta join or natural join here to reach intersection?
Does it return me empty relation if matching does not exist?
Upvotes: 0
Views: 964
Reputation: 18408
Yes it should return the empty relation if no matching tuples appear in the joined relations.
And yes, intersection is a special case of natural join ergo natural join is a generalization of intersection and ergo natural join can "replace" intersection wherever intersection can be used. (But you should mind that your particular use case is NOT one where "intersection can be used" - and the reason is precisely what you mentioned : the schema's aren't identical. Don't put the horse behind the cart.)
Upvotes: 2
Reputation: 27424
You can project A2
over id1
and id2
and then intersect the result with a1
, or you can also apply a natural join and then project the result again over id1
and id2
.
This two different approaches produce the same result.
Upvotes: 0