2006/4/8, Philippe Poelvoorde <[EMAIL PROTECTED]>:
> Hi,
>
> 2006/4/8, Dan Buettner <[EMAIL PROTECTED]>:
> > Seems like what you're looking for is a way to query your database
> > more efficiently/quickly, and still find all links in either
> > direction.
> >
> > I think the use of a UNION statement should allow this.  Basically
> > write your query twice, joining on id1 the first time and id2 the
> > second time, with "UNION" in the middle.
>
> To select reciprocal friends of Dan (that is a friends relationship in
> both ways), I would do that :
> select p.name from friends f1, friends f2, people p
> where p.peopleid=f1.id1 and f1.id2=1
>           AND f1.id2=f2.id1
>          AND f1.id1=f2.id2
> UNION select p.name from friends f1, friends f2, people p
> where p.peopleid=f1.id2 and f1.id1=1
>          AND f1.id1=f2.id2
>          AND f1.id2=f2.id1;
>
> +------+
> | name |
> +------+
> | Matt |
> +------+
>
> But I don't think it's the best solution in term of performance :)

Sorry, can anyone comment this query ? How would you find the list of
symetric friend of Dan ?

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to