dbTalk Databases Forums  

Asymmetric self-join?

comp.databases comp.databases


Discuss Asymmetric self-join? in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
metaperl
 
Posts: n/a

Default Asymmetric self-join? - 02-04-2007 , 01:28 AM






Let's say I have a lil ole table like this:

animal amount
cat 12
dog 4
horse 90000


and let's say I want an output table that is the self-join of that
table, but with two things
filtered out:
1 - rows with the same animal (i.e. no rows like:
cat 12 cat 12

2 - either of the rows which contain the same thing but in reverse
order... meaning:
cat 12 dog 4 OR dog 4 cat 12 but not both


Is this possible in a single SQL query or must PL/SQL or program code
be written?


Reply With Quote
  #2  
Old   
Lennart
 
Posts: n/a

Default Re: Asymmetric self-join? - 02-04-2007 , 02:42 AM






On Feb 4, 8:28 am, "metaperl" <metap... (AT) gmail (DOT) com> wrote:
Quote:
Let's say I have a lil ole table like this:

animal amount
cat 12
dog 4
horse 90000

and let's say I want an output table that is the self-join of that
table, but with two things
filtered out:
1 - rows with the same animal (i.e. no rows like:
cat 12 cat 12

2 - either of the rows which contain the same thing but in reverse
order... meaning:
cat 12 dog 4 OR dog 4 cat 12 but not both

Is this possible in a single SQL query or must PL/SQL or program code
be written?
You can use a theta-join. Example:

select T1.*,T2.* from T T1, T T2 where T1.animal > T2.animal

ANIMAL AMOUNT ANIMAL AMOUNT
---------- ----------- ---------- -----------
dog 4 cat 12
horse 90000 cat 12
horse 90000 dog 4
parrot 4 cat 12
parrot 4 dog 4
parrot 4 horse 90000


/Lennart



Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.