| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Bidirectional Binary Self-Joins
"Marshall" <marshall.spight_at_gmail.com> wrote in message
news:1175374919.556254.272810_at_n59g2000hsh.googlegroups.com...
> On Mar 31, 1:10 pm, "JOG" <j..._at_cs.nott.ac.uk> wrote:
> > On Mar 31, 3:37 pm, "Marshall" <marshall.spi..._at_gmail.com> wrote:
> >
> > > D'oh!
> >
> > > I believe it was earlier stated that each team could play
> > > only once per day, thus both (12-Dec, Hope) and
> > > (12-Dec, Calvin) must be unique. This is sufficiently
> > > annoying with RVAs that I am now inclined to go back
> > > to the non-RVA model.
> >
> > > (date, team1, team1score, team2, team2score)
> > > unique(date, team1)
> > > unique(date, team2)
> > > check(team1 < team2)
> >
> > > The third constraint's "<" can be any order relation,
> > > and canonicalizes the tuple type.
> >
> > This is a good tip - I use this sort of constraint a lot, especially
> > in self-joins to guarantee uniqueness.
> >
> > > Queries like "what games did Hope play in" and
> > > "what teams scored over 40 points" go back to
> > > being trivial.
> >
> > Unfortunately we are left with that same issue - the choice of team1
> > and team2 is arbitrary, and as David or Paul pointed out, it means I
> > have to do some jiggery pokery on my queries to consider both these
> > different attributes simultaneously, even though they are playing the
> > same roles. This obviously isn't going to kill us, but it doesn't seem
> > elegant, so it niggles.
>
> Get over it. :-)
What if, instead of soccer, the game is Chinese checkers, where there can be up to six contenders in one game? Or how about tournament bridge, with say 30 pairs competing in a match?
You could end up writing an awful lot of "or" expressions.
>
>
>
>
>> select team2 from teams where score2 > 40
> select team1 from teams where score1 > 40
> union
>
>
>
> create view SGames as
> select date, team1 as team, score1 as score from games union
> select date, team2 as team, score2 as score from games;
>
>
>
>
>
>
>
> >
![]() |
![]() |