X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D3C493A41BD for ; Sat, 6 Nov 2004 23:13:39 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 02915-04 for ; Sat, 6 Nov 2004 23:13:28 +0000 (GMT) Received: from pop.sanbrunocable.com (pop.sanbrunocable.com [65.172.230.120]) by svr1.postgresql.org (Postfix) with ESMTP id 833B43A41A9 for ; Sat, 6 Nov 2004 23:13:29 +0000 (GMT) Received: from oss4u.com (cpe-65-172-234-54.sanbrunocable.com [65.172.234.54]) by pop.sanbrunocable.com (8.11.6/8.11.6) with SMTP id iA6NC0805774 for ; Sat, 6 Nov 2004 15:12:01 -0800 Received: (qmail 15566 invoked from network); 6 Nov 2004 23:09:34 -0000 Received: from tiburon.oss4u.com (192.168.1.4) by gw.oss4u.com (192.168.1.1) with ESMTP; 06 Nov 2004 23:09:34 -0000 From: "Uwe C. Schroeder" Organization: OSS4U, LLC To: pgsql-general@postgresql.org Subject: SQL question Date: Sat, 6 Nov 2004 15:13:22 -0800 User-Agent: KMail/1.5.3 MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Description: clearsigned data Content-Disposition: inline Message-Id: <200411061513.25914.uwe@oss4u.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/231 X-Sequence-Number: 68312 =2D----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Here's a question for the SQL guru's out there, which I've been trying to=20 solve for the last couple of hours. There's got to be a solution to this, b= ut=20 somehow I can't find it. Tables: table1 ( uid int PK, uname varchar(64) ) table2 ( uid int FK to table1, xuid int FK to table 1 ) table3 ( uid int FK to table1, yuid int FK to table1 ) There might be more tables of the type like table2 and table3, but I'd alre= ady=20 be happy to solve the puzzle with the 3 tables above. Ok, assume table1 is the master table - in my case a table used for login=20 authentication (some columns removed above) table2 and table3 are tables where the uid always references to the uid in= =20 table1. The second "uid" (xuid and yuid in this example) references to=20 another uid record in table1. The problem is that there may or may not be=20 entries in table2 (or table3) referencing a specific uid in their second ui= d=20 field. Maybe some data: table1: 1 test1 2 test2 3 test3 table2: 1 2 1 3 3 1 table3: 1 2 2 3 3 2 What I want to do in a view is the following resultset: uid uname xuid yuid 1 test1 2 2 1 test1 3 2 test2 3 3 test3 1 3 test3 2 So basically I want to know which uid is connected to which uid, one=20 relationship per row. So xuid and yuid shall be identical if records exist = in=20 both table2 and table3 or the value shall be NULL if a corresponding record= =20 can't be found in either table2 or table3. Can anyone here help me out?=20 Thanks a lot UC =2D -- Open Source Solutions 4U, LLC 2570 Fleetwood Drive Phone: +1 650 872 2425 San Bruno, CA 94066 Cell: +1 650 302 2405 United States =46ax: +1 650 872 2417 =2D----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFBjVqVjqGXBvRToM4RAhk5AKCjjGc4VilA45PnPZoKluTNYUP6FACgrRQq XFIvkCIJHyz7TvvV/XxL4Lk=3D =3D/vxG =2D----END PGP SIGNATURE-----