X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 5C0FA47636B for ; Tue, 13 May 2003 12:11:27 -0400 (EDT) Received: from t-9.net (unknown [64.246.36.43]) by postgresql.org (Postfix) with SMTP id 9DDC1474E42 for ; Tue, 13 May 2003 12:11:22 -0400 (EDT) Received: (qmail 8208 invoked by uid 0); 13 May 2003 14:16:31 -0000 Received: from localhost (HELO seahat.com) (127.0.0.1) by localhost with SMTP; 13 May 2003 14:16:31 -0000 Received: from 65.102.128.233 (SquirrelMail authenticated user snubber@seahat.com) by fordparts.com with HTTP; Tue, 13 May 2003 09:16:31 -0500 (CDT) Message-ID: <11523.65.102.128.233.1052835391.squirrel@fordparts.com> Date: Tue, 13 May 2003 09:16:31 -0500 (CDT) Subject: N all-way relationship From: "Ryan" To: X-Priority: 3 Importance: Normal X-Mailer: SquirrelMail (version 1.2.8) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, hits=-5.7 required=5.0 tests=BAYES_01,MSG_ID_ADDED_BY_MTA_3 version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/227 X-Sequence-Number: 13392 OK SQL wizards, chew on this. I am trying to visualize the best way to store and retrieve information in a an all-way relationship with an unknown number of elements. This is largely related to cross referencing part numbers. You have a factory part and any number of aftermarket vendors making compatible parts for that factory part (they are all theoretically interchangeable). So given a factory number of 123. if one vendor makes the part 456 that equates to 123, then, well that's quite easy. You need a lookup table that corresponds 123 to 456, and for reverse lookups you store 456 - 123. (you have a whopping two records) But if you throw in a few more vendors and things get a bit more crazy. All of a sudden parts 789, ABC and XYZ now all copy 123 (and by proxy, 456) so you could keep doing things the structured way, 123 - 456 123 - 789 123 - ABC 123 - XYZ 456 - 123 456 - 789 456 - ABC 456 - XYZ ... XYZ - 789 XYZ - ABC You get the idea, you now have 20 records for five parts. Now multiply that by the hundreds of thousands. If another vendor added a compatable part, you just added 10 new records. Now to the meat of my question. Is there a better way to do this? How could I store all this information in a single record with the unknown number of matches, yet at any point ask for a single part and get all the parts that would be compatible? Without breaking joins? (Each vendor has its own price book.) It just seems to me that there would be a more elegant solution. Ryan