Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

[MySQL] hierachy problem ...

 
   Database Help (Home) -> PHP SQL RSS
Next:  SQL and VB- how do u count records  
Author Message
pounch

External


Since: Feb 17, 2005
Posts: 4



(Msg. 1) Posted: Thu Feb 17, 2005 9:40 am
Post subject: [MySQL] hierachy problem ...
Archived from groups: alt>php>sql (more info?)

Hello,

I have a table which have these fields:
- id
- idParent
- label

I would like to display each field and his children but each parent may
have no child.

Example:
A
AA
AB
AC
B
C
CA
CB
....

I can't write the request, could you help me? :-p
Thanks

Dams

 >> Stay informed about: [MySQL] hierachy problem ... 
Back to top
Login to vote
News Me

External


Since: Feb 03, 2005
Posts: 18



(Msg. 2) Posted: Thu Feb 17, 2005 9:40 am
Post subject: Re: [MySQL] hierachy problem ... [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

pounch wrote:
 > Hello,
 >
 > I have a table which have these fields:
 > - id
 > - idParent
 > - label
 >
 > I would like to display each field and his children but each parent may
 > have no child.
 >
 > Example:
 > A
 > AA
 > AB
 > AC
 > B
 > C
 > CA
 > CB
 > ...
 >
 > I can't write the request, could you help me? :-p
 > Thanks
 >
 > Dams

In your example, is A, B, C just the id from Parent or does it also have
a label? Assuming it does:

SELECT Parent.label, Child.id, Child.idParent, Child.label
FROM Parent, Child
WHERE Parent.id=Child.idParent

 >> Stay informed about: [MySQL] hierachy problem ... 
Back to top
Login to vote
pounch

External


Since: Feb 17, 2005
Posts: 4



(Msg. 3) Posted: Thu Feb 17, 2005 10:40 am
Post subject: Re: [MySQL] hierachy problem ... [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Ok I think I have the solution:

select t1.label as Parent, t2.label as Child from table t1
left join table t2
on t1.id=t2.idParent
order by t1.label, t2.label

This results in:

+----------------+
| Parent | Child |
+----------------+
| A | AA |
| A | AB |
| A | AC |
| AA | AAA |
| AA | AAB |
| AB | ABA |
| AAB | AABA |
| B | |
| C | CA |
| C | CB |
+----------------+

and so on ...

Now I have to find a php script that displays the correct tree ... Wink
 >> Stay informed about: [MySQL] hierachy problem ... 
Back to top
Login to vote
pounch

External


Since: Feb 17, 2005
Posts: 4



(Msg. 4) Posted: Thu Feb 17, 2005 10:40 am
Post subject: Re: [MySQL] hierachy problem ... [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Here is my request for now:

select p.label as Parent, c.label as Child from table p
join table c on c.idParent=p.id
order by p.label


But the children with no parent are not displayed ...
what's wrong?



pounch wrote:
 > Hello,
 >
 > I have a table which have these fields:
 > - id
 > - idParent
 > - label
 >
 > I would like to display each field and his children but each parent may
 > have no child.
 >
 > Example:
 > A
 > AA
 > AB
 > AC
 > B
 > C
 > CA
 > CB
 > ...
 >
 > I can't write the request, could you help me? :-p
 > Thanks
 >
 > Dams
 >> Stay informed about: [MySQL] hierachy problem ... 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
php + MySQL problems - I'm trying to get php + MySQL running on my web server. I tested the setup on an old RH8 server install that I was going to upgrade; everything worked fine. So I wiped out the old RedHat, installed Fedora Core 2, and repeated the installation. No dice...

Accounts in Mysql - Hello, Learning about Mysql Accounts, there is something I like to ask for. I have made some database tests as root mysql with [gastonv@telenetPC ~]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL....

php and mySql - I get an error message while trying to follow these procedures: http://www.howtoforge.com/intrusion-...on-ubuntu-7.10 Here is the error: Fatal error: Call to undefined function mysql_connect() in /var/www/adodb5/drivers/adodb-mysql.inc.php on line 363..

simple question I think...about PHP/mySQL - I want to make a website that starts with letters A thru Z . Click on the letter A you get a list of surnames beginning with A.... Click on surname A..... you get a table with all the information from a mySQL on the people with that surnames. My simpl...

Testing PHP and MySQL - Hello, I'm working in FC8 and I like to use MySQL with PHP. I have installed: [gastonv@telenetPC ~]$ yum list installed | grep php php.i386 5.2.4-3 installed php-cli.i386 5.2.4-3 installed php-common.i386 ...
   Database Help (Home) -> PHP SQL All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]