If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > 2 tables interacting with each other

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-18-09, 22:01
chronox chronox is offline
Registered User
 
Join Date: May 2009
Posts: 2
2 tables interacting with each other

Hi guys,
i've been faced with this dilema about basically designing a sql database.

my requirement is for two tables.
first table product.
second table ingredient.

I have a set of ingredients = IDs and text

Similarly with with product = ID and text

heres the problem, product1 = (ingredient1 + 2 + 4 etc..);
each product in the products table is made up of a set of ingredients.

What i want is, when I select any set of ingredients, it should yeild all the products the selected ingredients are in.

how do i go about it?
i designed a basic model
ingredients table and products table are connected via a mapping table.
the mapping will hold all IDs.
product 1 = ingr 1
product 1 = ingr 2
product 1 = ingr 4

thats how it is. But i wana know if there is anny better way of going about this. specially if
1= i want to add another table like ingredients and connect it to products
2= what if I want two similar ingredients two hold one ID? (its not possible .. but.. )

any help / alternatives is appreciated.
Reply With Quote
  #2 (permalink)  
Old 05-19-09, 04:54
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
Originally Posted by chronox
my requirement is for two tables.
first table product.
second table ingredient
I think the correct technical term you're looking for is coursework
Reply With Quote
  #3 (permalink)  
Old 05-19-09, 06:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by chronox
1= i want to add another table like ingredients and connect it to products
why would you do that? the three tables you already have (products, ingredients, and the mapping table) are sufficient

Quote:
Originally Posted by chronox
2= what if I want two similar ingredients two hold one ID?
why would you do that? there is no need
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 05-19-09, 13:02
chronox chronox is offline
Registered User
 
Join Date: May 2009
Posts: 2
thanks r937!,

So you think my approach is right? and theres not a better way?

I wouldnt do those, its true, but I was thinking of a future scenario "what if i add.."!

and this isnt a coursework. I wish you'd atleast mention Google..!
Reply With Quote
  #5 (permalink)  
Old 05-19-09, 13:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by chronox
I wish you'd atleast mention Google..!
i'd be happy to: Let me google that for you
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On