2

My Database structure is like follows

id category    parent
-------------------------
1  Programming 
2  Database    Programming
3  MySQL       Database

Now when i query for MySQL, i should get the result as

MySQL -> Database -> Programming

I received some suggestions that, i can do it using Stored Procedures. But it will make my query slow.

5
  • see this: mikehillyer.com/articles/managing-hierarchical-data-in-mysql Commented Aug 24, 2012 at 5:23
  • +1 for representation & very innocent question... Commented Aug 24, 2012 at 5:27
  • thanks Omesh & Waasim... Commented Aug 24, 2012 at 5:30
  • Omesh, your link was much helpful. It solved my purpose for now. But when the application grows, the number of category grows, it may slow down my query because for each depth, i need a join. Commented Aug 24, 2012 at 5:32
  • Omesh, you provided me something which i exactly wanted Commented Aug 24, 2012 at 5:35

3 Answers 3

1

This is just what JOINs are made for.

Sign up to request clarification or add additional context in comments.

Comments

0

means you want to display output

Database -> Programming

this format.

I tried one query

 select category,"->",parent from table where id =2;

it gave output

category ->  parent
Database -> Programming   

2 Comments

Thanks Sandy, But i need it further. The output should be MySQL -> Database -> Programming (instead of MySQL -> Database)
try this one select "MySQL","->",category,"->",parent from table where id =2;
0

Check this query and let me know if it works or not( testtube is my table name )---

SELECT a.category,  "->", a.parent,  "->", b.parent
FROM testtube AS a
INNER JOIN testtube AS b
WHERE a.parent = b.category
AND a.category =  "MySql"
LIMIT 0 , 30

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.