Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jon3k
Starting Member
49 Posts |
Posted - 2005-02-04 : 18:45:50
|
| I've setup a table called category:id - int, primary key, yadda yaddaparent_id = intdepth = intcattitle = varchar(50)And I've written a query that will take each record, and via a reflexive relationship, join each record to its parent:SELECT category.cattitle, subcat.cattitle FROM category INNER JOIN category subcat ON subcat.parent_id = category.idAnd this all works fine and dandy, except that there's no useful and efficient way to output the results. It simply looks at each record and joins it to its parent. What would be the proper grouping/ordering to get a nice clean outputtable (is that a word?) result set?I'd likeCategory1--SubCat1----SubSubCat1Category2--SubCat2----SubSubCat2----SubSubCat2Category3--SubCat3--SubCat3Etc, etc.Anyone ever pulled this off before? Is there a better way to do this? I'd really like to do it with one query, and output it in a single pass, without having to loop over the result set several times.(mysql and php by the way). |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-02-04 : 18:52:02
|
quote: Originally posted by jon3k (mysql and php by the way).
I would post your question in the mysql forum over at dbforums.com then as any solution provided here would be for SQL Server.Tara |
 |
|
|
jon3k
Starting Member
49 Posts |
Posted - 2005-02-04 : 18:57:31
|
| I'll try dbforums also, thanks. |
 |
|
|
arpp
Yak Posting Veteran
61 Posts |
Posted - 2005-02-06 : 12:06:42
|
| Look at this posting,It might help you out.http://www.sqlteam.com/item.asp?ItemID=8866 |
 |
|
|
|
|
|