Search Postgresql Archives

Re: Categories and Sub Categories (Nested)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Apr 19, 2006, at 14:44 , Martin Kuria wrote:

I have a postgresql database Table Categories which has the structure like this

Cat_ID | Parent_ID | Name
------------------------------------
1 | 0 | Automobiles
2 | 0 | Beauty & Health
3 | 1 | Bikes
4 | 1 | Cars
5 | 3 | Suzuki
6 | 3 | Yamaha
7 | 0 | Clothes

According to the above Database data, Suzuki and Yamaha are the Subcategories of Category Bikes and Bikes in turn is the Subcategory of Automobiles.

If you're looking at having a potentially deep hierarchy, I'd recommend taking a look at nested sets, which also allows you to keep everything in one table.

http://www.intelligententerprise.com/001020/celko.jhtml? _requestid=145525]

By the way, the method you outline above is often called the adjacency list model.

Hope this helps.

Michael Glaesemann
grzm myrealbox com





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux