gork Posted July 18, 2009 Report Share Posted July 18, 2009 Hello everyone,I'm fairly new to this whole SQL thing and I'm having trouble figuring out a particular problem. I was hoping you guys could point me in the right direction. So say for example you wanted to make a website for sandwich recipes and everything about the sandwich recipe could be search able. If you wanted to see all the sandwiches that could be made that included peanut butter, chicken, and a knife, that would be completely possible. Now the problem I can't figure out is how to handle all the duplicates. What I mean is that any given sandwich can have any number of given ingredients...and every given ingredient can have any number of sandwiches. I have no idea how to represent this in the database. Help me out? Link to comment Share on other sites More sharing options...
gork Posted July 19, 2009 Author Report Share Posted July 19, 2009 Well no one is responding, so maybe I'll add my thoughts. I was thinking in one table I could be the sandwich name and the sandwich recipe instructions. Another table could be the ingredients. Yet another table could be the tools used. The problem is, is that I don't know where to go from here...I don't know how to link them. How do I connect all the sandwiches that use peanut butter to the peanut butter in the ingredients table? Then how would I additionally link jam to the pb and j entry. The only way I can think of is just endless repetition. But surely there is an easier way? Like I said...I'm new to this whole thing so if someone could please point me in the right direction here, I would greatly appreciate it. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 20, 2009 Report Share Posted July 20, 2009 You need another table to hold the relationships. The sandwich table would have an ID for each sandwich, and the ingredients table would have an ID for each ingredient. A third table would have a column for the sandwich ID and a column for the ingredient ID, which would signify that a certain sandwich uses a certain ingredient. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now