At 22:53 06.09.01, you wrote:
>mysql> SELECT receiver_id, associate_of, user_name FROM receivers;
>+-------------+--------------+-------------+
>| receiver_id | associate_of | user_name |
>+-------------+--------------+-------------+
>| 1 | 0 | arnold |
>| 2 | 0 | barney |
>| 3 | 0 | cecilia |
>| 4 | 2 | diana |
>| 5 | 2 | elmer |
>| 6 | 3 | fred |
>+-------------+--------------+-------------+
>6 rows in set (0.00 sec)
>
>It is a recursive table design, meaning that a person can have a boss. The
>boss' id is stored in the associate_of column. Eg. elmer is barney's
>associate, barney is boss of elmer, and diana
>
>Let's say I only know the user_name 'barney', and I would like to select
>all his associates.
mysql does not support sub-selects, thus you have to write it using a join
with the same table twice, something like (untested, out of my head);
select person.receiver_id, person.associate_of, person.user_name from
receivers as person, receivers as boss where boss.user_name='barney' and
person.associate_of=boss.receiver_id;
this should return you diana and elmer, but not barney, because he is not
his boss.
hth,
henning
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php