Cartesian Product in Relational Algebra
Asked Answered
S

1

6

I'm a total begginer in Relational Algebra and I don't manage to fully understand how cartesian product works.

I want to know what happen in cartesian product when my two table have common attributes. I have no problem to understand when both table don't have any attribute in common.

For instance I tried to understand on example I made myself.

T1                          T2
----------                  -----------
A   B   C                   A    B   D
1   4   7                   1    4   8
2   5   3                   2    9   5
4   7   1                   7    3   2

If I want to do T1 x T2, when I want to write the line that is the concatenation of the first line of T1 A=1 , B=4 , C=7 and the second line of T2 A=2 ,B=9 ,C=5 , what happen to the column A and B ?

If you could show me the result of T1 x T2 it would be really useful!

Sillabub answered 20/9, 2017 at 12:1 Comment(2)
Please give a reference to your relational algebra variant. Many algebras have relations with ordered attributes, which can have duplicate names; so they can calculate a product of any two relations.Combine
Possible duplicate of Cartesian products of tables that contains same columnsCombine
M
7

Edit: As discussed on comment section. I'm editing this answer for a proper understanding of the question.

As this is a possible duplicate, refer to this link: Cartesian products of tables that contains same columns

First, it depends on the algebra that you are using. For some, the cartesian product can be done between tables with common attributes, similar to a cross join, and on other algebras the cartesian product is not permitted, so you would have to rename the attributes.

p.s: Look up Cross Joins as they are similar to a cartesian product but with no conditions to join, see expected result of a cross join of your example tables:

    T1                      T2                T1 X T2
----------              -----------     =    ----------------------------
A   B   C                A    B   D          T1.A T1.B T1.C T2.A T2.B T2.D
1   4   7                1    4   8           1     4   7    1    4    8
2   5   3                2    9   5           1     4   7    2    9    5
4   7   1                7    3   2           1     4   7    7    3    2
                                              2     5   3    1    4    8
                                              2     5   3    2    9    5
                                              2     5   3    7    3    2
                                              4     7   1    1    4    8
                                              4     7   1    2    9    5
                                              4     7   1    7    3    2 

refer link: What is the difference between Cartesian product and cross join?

Also, i highly recommend you to check this out and try it yourself!

RelaX - relational algebra calculator http://dbis-uibk.github.io/relax/index.htm

Minion answered 20/9, 2017 at 12:11 Comment(8)
When i try my example in the calculator you gave me I get join would result in non unique column names; the following columns appear in both relations: A, B. So Should I conclude that I can't make a cartesian product without renaming A and B ?Sillabub
Oh snap! I misunderstood your question. I'll edit my answer. But to correct it here already. Cartesian product is a case of natural join where the joined relations don't have any attribute names in common. What i misunderstood for a Cross Join, which then would give you some valid result. And, yes, you should conclude that.Minion
Errr I think the fault is mine I dindn"t know there were a difference beetweens Cross Product and Cartesian Product! But what i meant was cross product and that's what i used on the calculator (Named cross join on the website) ! And it gave me the error message i wrote before.Sillabub
Strange. I used the same data you provided as example here and it gave a valid result: Printscreen 1 Printscreen 2Minion
@Sillabub & VictorMedeiros Depends on the algebra variant. See my comments on the question.Combine
@Combine Yes! On my answer i refer to the same link. I'm kinda new here so i didn't remember to mark as possible duplicate.Minion
@Sillabub & VictorMedeiros Ha ha missed a link to my own answer. Notice that that link explains that this answer is only correct for certain algebras, and for others wrong, hence is misleading, and the question doesn't give an algebra, so I wish the asker good luck. I find "more technical" odd--it's just more comprehensive since the question (like this one) is general. The need for a lot of cases & notions is because so many "algebras" are ridiculously complicated (and sometimes not "algebras" at all). Generally motivated by SQL apologetics.Combine
You are completely correct, i'll edit it so it's not so confusing.Minion

© 2022 - 2024 — McMap. All rights reserved.