If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > relation joins with itself

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-30-03, 00:13
borislava borislava is offline
Registered User
 
Join Date: Oct 2003
Posts: 1
Exclamation relation joins with itself

it seems simple but...
when you join relation r with itself what is the output - relation R or something different.
any help will be greatly appreciated!
Borislava
Reply With Quote
  #2 (permalink)  
Old 10-30-03, 03:41
Krastio Krastio is offline
Registered User
 
Join Date: Oct 2003
Location: Sofia
Posts: 16
Depends ...
If relation between table A and A is "PK - PK" then you will see just extanded table A - table AA.
Otherwise - no one knows, data depended.

Last edited by Krastio; 10-30-03 at 04:44.
Reply With Quote
  #3 (permalink)  
Old 11-02-03, 18:24
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
According to the relational algebra, when you join two relations that have identical headers, you're performing a set intersection. Since the intersection of a set with itself returns itself, it follows that a relation joined with itself returns itself.

In SQL you have to rename identical columns which makes a mess. I think that's what Kristio was driving at...

But, SQL is <b>not</b> the relational algebra and it doesn't even deal with proper relations. In SQL "A NATURAL JOIN A" is not a valid expression. You have to phrase it as a SELECT statement so there's really no such thing as joining a SQL table with itself.

If you write a statement of the form SELECT A1.* FROM A A1 INNER JOIN A A2 ON A1.PK = A2.PK, you'll get the same thing as A |><| A in relational algebra, namely, A.
Reply With Quote
  #4 (permalink)  
Old 11-08-03, 11:21
Adrian Jones Adrian Jones is offline
Registered User
 
Join Date: Nov 2003
Location: Currently New York; Usually UK
Posts: 4
Re: relation joins with itself

PK-PK should produce a set of one record.

PK-FK, where the relationship is recursive (e.g. RecA parents RecB, C and D) will return a set of the immediate children.

'FK-FK' should produce a set of all records that have that attribute in common, e.g. they all belong to the same parent; they all happened on the same date; they all total 3, or whatever.

That parent table may be just implied, rather than represented by an actual table. An example of this is the set of Dates, which often has a number of related sets -- same month, same quarter, same year, etc -- where to express in an actual table all the possible combinations would be tedious, to say the least. Nonetheless, the implied data sets still exist.
Reply With Quote
  #5 (permalink)  
Old 11-08-03, 11:36
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
Re: relation joins with itself

Quote:
Originally posted by Adrian Jones
PK-PK should produce a set of one record.
So, supposing relation Foo is:

Code:
PK  A           B
1    alpha      antelope
2    beta       buzzard
3    gamma   centipede
Can you show me the expression that will return a relation of one tuple?
Reply With Quote
  #6 (permalink)  
Old 11-08-03, 18:08
Adrian Jones Adrian Jones is offline
Registered User
 
Join Date: Nov 2003
Location: Currently New York; Usually UK
Posts: 4
Re: relation joins with itself

Sco08y,

I'm sorry -- you are correct.

I'm thinking one record per record, so to speak, which is the same as saying the entire dataset.
Reply With Quote
  #7 (permalink)  
Old 11-08-03, 18:58
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
Re: relation joins with itself

Quote:
Originally posted by Adrian Jones
Sco08y,

I'm sorry -- you are correct.

I'm thinking one record per record, so to speak, which is the same as saying the entire dataset.
Okay, that makes sense. The question was ambiguous as to exactly what kind of join was being performed, so I thought maybe you were talking about some kind of strange SQL operation.
Reply With Quote
  #8 (permalink)  
Old 11-13-03, 03:29
satish_ct satish_ct is offline
Registered User
 
Join Date: Nov 2003
Location: Bangalore, INDIA
Posts: 333
Thumbs up Re: relation joins with itself

Hi,

If U join a relation R with itself , it will create a cross product. For example if the relation R has N tuples, then the Output will be 2^N Tuples.
__________________
SATHISH .
Reply With Quote
  #9 (permalink)  
Old 11-13-03, 10:01
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
Re: relation joins with itself

Quote:
Originally posted by satish_ct
Hi,

If U join a relation R with itself , it will create a cross product. For example if the relation R has N tuples, then the Output will be 2^N Tuples.
If you renamed all of R's attributes and joined the result against R, you would indeed get a cross product, but it would have N^2 tuples.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On