There’s a good-looking article over at mysql.com outlining various ways of managing hierarchical data. I think it provides a full solution to your question, and shows various less simple, but faster approaches (e.g. Nested Sets).
More Related Contents:
- Using MySQL query to traverse rows to make a recursive tree
- mysql stored procedure that calls itself recursively
- get a recursive parent list
- MySQL Recursive get all child from parent
- MySQL how to fill missing dates in range?
- ‘IF’ in ‘SELECT’ statement – choose output value based on column values
- Why does MYSQL higher LIMIT offset slow the query down?
- How to split the name string in mysql?
- Normalization in MYSQL
- Is there a REAL performance difference between INT and VARCHAR primary keys?
- How to set a maximum execution time for a mysql query?
- MySQL select statement with CASE or IF ELSEIF? Not sure how to get the result
- Getting around MySQL “Can’t reopen table” error
- Can’t Create Entity Data Model – using MySql and EF6
- In MySQL, can I copy one row to insert into the same table?
- How to copy a row and insert in same table with a autoincrement field in MySQL?
- MySQL: Cloning a MySQL database on the same MySql instance
- MySQL sharding approaches?
- access denied for load data infile in MySQL
- Can MySQL convert a stored UTC time to local timezone?
- Whats the fastest way to lookup big tables for points within radius MySQL (latitude longitude)
- How to migrate SQL Server database to MySQL? [closed]
- How to insert selected columns from a CSV file to a MySQL database using LOAD DATA INFILE
- how to cast the hexadecimal to varchar(datetime)?
- My SQL Dynamic query execute and get ouput into a variable in stored procedure
- Postgres LEFT JOIN with WHERE condition
- MySQL – Using COUNT(*) in the WHERE clause
- How do you force mysql LIKE to be case sensitive? [duplicate]
- Delete all rows with timestamp older than x days
- In what order are MySQL JOINs evaluated?