Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested Tables

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Is it possible to have nested tables in the database? I am designing a webpage that needs to organize data into categories, subcategories, and below subcategories i'll have items.

So what I wanted to do was create a table with all categories, with each element of the table containing another table which is a subcategory. Each subcategory would then contain all the item records in it.

Is this possible using a SQL server such as MySQL? Thanks, any help appreciated.
 
There is no way (at least that I know of) to put a table inside a table with MySQL or any other SQL server that I am aware of. But, MySQL is a relational database management system (Relational being the key word). You structure the database so that different types of data are stored into different tables and then the tables are linked by defined relations.

In your example above I would do the following (disclaimer - I am not an expert DB developer so there might actually be a better way, but this is only how I would do it):

I would create three tables (catagories, subcatagories, items). Each catagory would have a field with some unique identifier as it's primary key (catagorykey). Each subcatagory would have a field containing the "catagorykey" of the catagory that it belongs to. Each subcatagory would also have a field with some unique identifier as it's primary key (subkey). Each item would have a field containing the "subkey" of the subcatagory that it belongs to.

Doing it this way, you would be able to find any items subcatagory by looking at it's relation field and find it's catagory by looking at the subcatagory's relation field.

I hope this helps
 
I don't think you'd really want to use a relational database at all for this. You'd want an environment that better adhered to the tree structure. I would recommend looking into LDAP ... a sort of object based database. But note, LDAP is extraordinarily fast on reads, but caterpillar slow on writes.

Good luck

brendanc@icehouse.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top