Michelle,
Thursday, December 05, 2002, 5:46:03 PM, you wrote:

MdB> I believe this question is solved by a join, but I
MdB> haven't really got a hang of it.

MdB> My table:
MdB> --------------------------------------
MdB> | uid | rootid | parentid | name     |
MdB> --------------------------------------
MdB> | 1   | 0      | 0        | name1    |
MdB> | 2   | 1      | 1        | name2    |
MdB> | 3   | 1      | 2        | name3    |
MdB> | 4   | 1      | 3        | name4    |
MdB> | 5   | 1      | 2        | name5    |
MdB> ...

MdB> How do I get this (WHERE uid=5):
MdB> ------------------------------------------
MdB> | rootid_name | parentid_name | name     |
MdB> ------------------------------------------
MdB> | name1       | name2         | name5    |
MdB> ------------------------------------------

MdB> If you need more info, please tell me.

Yes, JOIN is what you need.
Something like that:
mysql> SELECT t1.uid, t1.name, t2.name, t3.name
-> FROM mytest t1
-> LEFT JOIN mytest t2 ON t1.rootid=t2.uid
-> LEFT JOIN mytest t3 ON t1.parentid=t3.uid
-> WHERE t1.uid=5;
+------+-------+-------+-------+
| uid  | name  | name  | name  |
+------+-------+-------+-------+
|    5 | name5 | name1 | name2 |
+------+-------+-------+-------+
1 row in set (0.00 sec)



-- 
For technical support contracts, goto https://order.mysql.com/?ref=ensita
This email is sponsored by Ensita.net http://www.ensita.net/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Victoria Reznichenko
 / /|_/ / // /\ \/ /_/ / /__   [EMAIL PROTECTED]
/_/  /_/\_, /___/\___\_\___/   MySQL AB / Ensita.net
       <___/   www.mysql.com





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

Reply via email to