×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Nested Tables

Nested Tables

Nested Tables

(OP)
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.

RE: Nested Tables

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

RE: Nested Tables

(OP)
Hey thanks Hokey. that helped me a great deal.

Mohap

RE: Nested Tables

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close