X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 283199FB34B for ; Mon, 31 Jul 2006 04:39:26 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 58632-06 for ; Mon, 31 Jul 2006 04:39:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from smtpgate4.pacific.net.sg (smtpgate4.pacific.net.sg [203.81.36.24]) by postgresql.org (Postfix) with SMTP id 427F09FB34E for ; Mon, 31 Jul 2006 04:38:46 -0300 (ADT) Received: (qmail 4517 invoked from network); 31 Jul 2006 07:32:04 -0000 Received: from ppp8.dyn75.pacific.net.sg (HELO ?127.0.0.1?) (debraneys@210.24.75.8) by smtpgate4.pacific.net.sg with (DHE-RSA-AES256-SHA encrypted) ESMTPA; 31 Jul 2006 07:32:03 -0000 Message-ID: <44CDB1EF.6000508@debraneys.com> Date: Mon, 31 Jul 2006 15:31:59 +0800 From: John Tregea User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Joining a result set from four (4) tables Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200607/372 X-Sequence-Number: 25946 Hi, Can anyone help me with the following? I am setting up a series of permissions of my own making in pgSQL 8.1.4. I have the following tables; resource -- a list of available resources actions -- the actions available to the user policies -- the actions that are allowed to be performed on individual resources permissions -- matches users with granted actions on any resource users -- no surprises here I have read the docs about joins but cannot get my head around the correct syntax. The following SQL returns all actions for every resource SELECT permission.serial_id, resource.name, actions.name, actions.classification, actions.display_group, FROM permission, policies, resource, actions WHERE permission.user_id = '11' AND permission.related_id = policies.serial_id AND policies.status = 'Active' AND permission.status = 'Active'AND actions.status = 'Active'AND resource.status = 'Active' I need a list of permissions back for each resource that a user is authorised to access (when they login to their GUI). I also need to check (at user login) if every record in the chain (e.g. resource, action, policy and permission) is "Active" before the permission record is considered valid. The list for a resource called 'Scenarios' would look something like: 11900;"Scenarios";"Publish";"Action";"B" 11900;"Scenarios";"Authorise";"Action";"B" 11900;"Scenarios";"Create";"Action";"C" 11900;"Scenarios";"Update";"Action";"C" I am guessing it should be an inner join? but by reference book does not show joins on this many tables. Thanks in advance for any help. Regards John T