+4  A: 

You could use just one table category with columns:

  • category_id
  • category_name
  • parent_category_id

For main categories You set parent_category_id to null and You're done. :)

Michał Pękała
A: 

using normalization

2 table if one subcategory has only 1 parent category

Category

id

SubCat

id

category_id (linking to category)

you would have 3 tables if one subcategory can be part of more then 1 category. Two with your data, and one for linking the two together

Category

id

name....

SubCategory

id

name ....

Sub_Cat_Link

category_id

subcategory_id

thus searching for all subcatergories of a category would result in a statment like

select * from SubCategory where category_id = idOfACategory

Redlab
A: 

My principle is that if you can support N-levels you can support 2 levels (and not get in a pickle whan a fickle business user decides to have sub-sub-categories)

So i would create a categories table with the fields

  • id (autogenerated, sequence, UUID)
  • parent_id (foreign key to categories.id)
  • name
  • ...

In order to get the children of a category a

SELECT * FROM categories WHERE parent_id = :cat_id ;

You have to be a bit careful to keep it a acyclic directed graph, i.e. not create any loops, but that's about all.

Peter Tillemans