Question

Hi all I have an exam coming up and am not getting much help from the lecturer on two questions on the practice exam. She has provided the answer but has not responded to my questions about the answer, I'm hoping someone here would be able to explain why the answer is the way it is.

Consider the following two tables R and S with their instances:

R       S 
A B C  D E 
a x y  x y 
a z w  z w 
b x k    
b m j    
c x y    
f g h  

a) πA(R[natural join]B=D S)

the answer being (a,b,c), why isn't it (a,a,b,c)? does a projection make it distinct?


b) π A(R[natural join] B<>D S) 

the answer being (a,b,c,f), why is a an answer? b=d both times when values are x and z, so why is this being printed out?

Was it helpful?

Solution

[natural join] B=D

This is not a natural join because "natural join" is a join that joins relations exclusively over attributes of the same name. The construct you describe might in some places be labeled/termed an "equijoin" or so, but it is certainly noy a "natural join".

[natural join] B<>D

This is not a natural join because "natural join" is a join that joins together tuples of the argument relations if and only if the attribute values are equal.

You are being hopelessly mistaught and miseducated. Reference material : "an introduction to database systems", C.J.Date. It won't do you any good for your exams, but if you seek a later career in database technology it might be worthwhile to remember this.

But to answer your actual questions (in line with preceding answers) :

a) The attribute value 'a' cannot appear twice in the result of a projection, because a projection produces a relation, and a relation is defined to be a set, and sets cannot contain duplicates.

b) The [non-] natural join contains both the tuples (axyzw) and (azwxy). "First" tuple from R with "second" tuple from S, and other way round. The projection includes the result (a).

OTHER TIPS

a)In Relation Algebra, the projection operator provides duplicate elimination. In SQL this is not the default operation, but it is for relational algebra. Here is my source. At the moment, I can't recall why it does duplicate elimination, but this was my professor for databases and he is very knowledgeable. (I think it's because Relation Algebra uses set-logic and sets do not have duplicates.)

b)The joining of 2 tables creates a CROSS PRODUCT between the 2 tables. You have 6 rows and 2 rows. So the cross product is 6x2 = 12 rows. For row 1 of table R, you have a x y. This will be paired with x y AND z w resulting in [a x y x y] and [a x y z w]. The second pairing is valid for this relational algebra statement. Columns B and D do not match x != z.

a) πA(R[natural join]B=D S)
the answer being (a,b,c), why isn't it (a,a,b,c)? does a projection make it distinct?

In relational algebra, duplicate tuples are not permitted; that a main difference between sql (where distinct is needed) and relational algebra

b) π A(R[natural join] B<>D S) 
the answer being (a,b,c,f), why is a an answer? b=d both times when values are x and z, so why is this being printed out?

Natural join operation returns the set of all combinations of tuples in R and S, so in this case returns also tuples (a x y z w) and (a z w x y); thus a has to be in the resulting projection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top