Re: Many-to-many self-relationships
- From: Rick Bowlby <usenet@xxxxxxxxx>
- Date: Sun, 10 Jul 2005 08:19:06 +0100
On Fri, 8 Jul 2005 at 17:12:47, Stefan Rybacki <stefan.rybacki@xxxxxxx> wrote:
Rick Bowlby wrote:<snip>
<snip>1) A table of Links including 2 columns "Person1" and "Person2", as well as the other Link attributes. This would have the disadvantage of needing a union of two queries whenever you needed to retrieve all the links connected to a particular Person. It just feels wrong.
Its called m:n realation. And the first variant you presented is IMHO the correct one. Since it is exactly what a normalisation would do to one table that hold all information.<snip>
What do you mean by you need an union of two queries whenever you need to retrieve all links to a person?
What about a this example:
SELECT * FROM person JOIN link ON (person.person_id=link.person1 OR person.person_id=link.person2) WHERE person.person_id=xxx
This is one query and gives you all linked contacts to a specific person.
Regards Stefan
Thanks for the response Stefan.
What I had meant by needing two queries, was something like: SELECT * FROM person WHERE person_id IN ( SELECT person1 FROM link WHERE person2=XXX UNION SELECT person2 FROM link WHERE person1=XXX ) Your SQL is much better.
Rick -- Rick Bowlby
Use Reply-To for reply
.
- References:
- Many-to-many self-relationships
- From: Rick Bowlby
- Re: Many-to-many self-relationships
- From: Stefan Rybacki
- Many-to-many self-relationships
- Prev by Date: Database Design Question
- Next by Date: Re: Database Design Question
- Previous by thread: Re: Many-to-many self-relationships
- Next by thread: Re: Many-to-many self-relationships
- Index(es):
Relevant Pages
|
Loading