Hi All,
I'd like to develop something which has a concept like the
folders-and-files in your PC.
A folder can have subfolders and/or files. The subfolders themselves
have the same characteristics .
This characteristic can also be found in Google Newsgroup, aka Usenet.
A group can have many postings and many other groups.
I want to reapply this concept for listing contents for categories,
not unlike the categories one can find in Yahoo. For example:
The root has many categories: Electronics, Art, Entertainment, etc.
Under Electronics there are subcategories such as cameras, washing
machine and refrigerators. However, here's the twist:
When I select Electronics, I want all items under all subcategories to
be listed as well. That means I need to traverse to every descendant
categories to view all items under them.
If I start out with two tables, CategoryTable and ItemTable, how
should I design their relationship and how should the SQL query be
constructed ?
Any help in whatever form would be very much appreciated.
P.S.:
The CategoryTable, in my mind, should have at least these columns:
- categoryId (PK)
- categoryParentI d (To maintain the hierarchy structure)
The ItemTable
- itemId(PK)
- categoryId (FK pointing towards CategoryTable.c ategoryId.
Many-to-one relationship)