View Single Post
Join Date: Aug 2007
Posts: 773
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 105
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: Database Design Question

 
0
  #2
Dec 4th, 2008
I would have another table, related_wigets, with the following structure:

widgetid (number, PK, FK)
related_widgetid (number, PK, FK)

When someone wants to relate widget with widgetid = 1 to widget with widgetid = 2, do an insert like so:
  1. INSERT INTO related_widgets (widgetid, related_widgetid)
  2. VALUES (1, 2)

When you want a full list of which widgets are related to widget with widgetid = 3, the following query will give you a complete list:

  1. SELECT * FROM related_widgets
  2. WHERE widgetid = 3 OR related_widgetid = 3

Hope this helps,
darkagn
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote