1

I am trying to understand what will be the result of performing a natural join between two relations R and S, where they have no common attributes.

By following the below definition, I thought the answer might be an empty set:
Natural Join definition.
My line of thought was because the condition in the 'Select' symbol is not met, the projection of all of the attributes won't take place.
When I asked my lecturer about this, he said that the output will be the same as doing a cartezian product between R and S.
I can't seem to understand why, would appreciate any help )

Yaoub
  • 21
  • 1
  • 4
  • 2
    I'm voting to close this question as off-topic because this belongs in a math-related site in the stack exchange network. – Tagc Jan 03 '18 at 16:05
  • If you really want to help yourself then 1. Force yourself to clearly identify *& express what you mean by the unclear "the condition in the 'Select' symbol is not met", "the projection of all of the attributes won't take place" and your particular use of "because". 2. Don't allow yourself to settle for unclear thinking & writing by prefacing it with "My line of thought was". – philipxy Jan 03 '18 at 22:36
  • [Please use text, not images/links, for text.](https://meta.stackoverflow.com/q/285551/3404097) – philipxy Jan 03 '18 at 22:39
  • Possible duplicate of [Natural join if no common attributes](https://stackoverflow.com/questions/14548543/natural-join-if-no-common-attributes) – philipxy Jan 03 '18 at 23:07
  • 1
    Where did you get that linked "definition"? It doesn't make sense. It isn't using relational algebra expressions--algebra operators input values but here somehow the sigma/restrict/select & x/product operators know about what names (r & s) were used in an expression used to specify an input value. It is sloppy pretend math involving some notation like a programming language with named values (of constants or variables). It might make sense if you include enough of the context it appeared in. Since it's nonsense it's no wonder you can't make sense of how the pi/projection [sic] works. – philipxy Jan 18 '18 at 00:49

2 Answers2

1

Natural join combines a cross product and a selection into one operation. It performs a selection forcing equality on those attributes that appear in both relation schemes. Duplicates are removed as in all relation operations.

There are two special cases:

• If the two relations have no attributes in common, then their natural join is simply their cross product.

• If the two relations have more than one attribute in common, then the natural join selects only the rows where all pairs of matching attributes match.

Notation: r s
Let r and s be relation instances on schema R and S
respectively.
The result is a relation on schema R ∪ S which is
obtained by considering each pair of tuples tr from r and ts from s.
If tr and ts have the same value on each of the attributes in R ∩ S, a
tuple t is added to the result, where
– t has the same value as tr on r
– t has the same value as ts on s

Example:

R = (A, B, C, D)
S = (E, B, D)
Result schema = (A, B, C, D, E)
r s is defined as:
πr.A, r.B, r.C, r.D, s.E (σr.B = s.B r.D = s.D (r x s))
Sudeep Devkota
  • 189
  • 1
  • 1
  • 11
  • Your text does not mention or explain that a certain projection follows the selection. (Although an example is in your code.) – philipxy Sep 04 '18 at 21:08
1

The definition of the natural join you linked is:

enter image description here

It can be broken as:

1.First take the cartezian product.

2.Then select only those row so that attributes of the same name have the same value

3.Now apply projection so that all attributes have distinct names.

If the two tables have no attributes with same name, we will jump to step 3 and therefore the result will indeed be cartezian product.

Sumeet
  • 8,086
  • 3
  • 25
  • 45