Jump to content

Using Multiple tables


TheFreak

Recommended Posts

I am making a list of products and every product fall under certain category.Now i want to add/edit category,but not necessary i would put product with it too.So i am guessing ill need to make another table for category.My question is,if i make another table for category then how will i link it to another table having the products and products details?

 

Suppose i have Category Motherboard and HDD,and under motherboard many products . So is there a way i can add/edit those category like i want to add Processors to it too or i want to edit HDD to harddisk and so that it affects the other table with product table too as when someone searches Motherboards,i want to show him all the products related to it

Link to comment
Share on other sites

Yeah well  i read about joints and i dont know how it will help me,my main problem is i have a category (suppose motherboards) then ill have a subcategory of that motherboard(suppose "Socket Type").Main catch is there can be many categories like that (like processors,HDD,RAM) and their respective subcategories,each motherboard having different details abt the subcategory...so i am not able to decide if i should make new tables for each category and their sub category or put all in one...problem to put all in one is,one category might have 2 sub category will others might have just one,so i think space will get wasted.Now if i make tables for every category there would be like 20 tables and i dont think thats good either.I know the solution is kinda simple too.

Link to comment
Share on other sites

On way to handle this would be two tables, as follow:

create table product (
  product_id
  product_name, ... etc.
  category_id
)

create table category(
  category_id
  category_name, ... etc.
  parent_category_id
)

 

... categories like that (like processors,HDD,RAM) and their respective subcategories,...
Is it just Category -> Sub-Category, or can Sub-Categories be further split into Sub-sub-categories. If you have just one sub-level, the queries should be easy.

 

Link to comment
Share on other sites

Yes i thought about that too,but the only things is i have 9 categories like that meaning there would be loads of table,wouldn't it harm in any way?

 

No, because is this model, there is only one category_table -- it's a foreign key to itself.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.