Jump to content

Recommended Posts

i have the \'category\' table in the following format

 

-------------------------------------------

id categoryname maincatid

-------------------------------------------

 

1 A 0

 

2 B 0

 

3 C 0

 

4 D 1

 

5 E 4

 

6 F 5

-------------------------------------------

 

As you can see A,B and C are the parent categorie. D is the subcategory of A, E is again subcategory of D and F is subcategory of E.

 

So the tree structure is like A-->D-->E-->F

 

Can i write a single query in which i will specify id for F. i.e 6 and it should fetch me all parent categories upto the topmost i.e. A

Link to comment
https://forums.phpfreaks.com/topic/1399-mysql-nested-query/
Share on other sites

I don\'t believe this is possible in one query. I scoured the mySQL page and couldn\'t find anything about this. I know it is definately possible using oracle, but not currently in mySQL. You could easily parse this recordset into PHP and get what you need.

Link to comment
https://forums.phpfreaks.com/topic/1399-mysql-nested-query/#findComment-4649
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.