From: stig erikson <stigerikson_nospam_@yahoo.se>
To: pgsql-sql@postgresql.org
Subject: Re: A Not Join
Date: Mon, 21 Nov 2005 21:16:13 +0100
Message-ID: <dlta4i$2hvu$1@news.hub.org> (raw)
In-Reply-To: <43677B35.6010005@lani.co.za>
References: <43677B35.6010005@lani.co.za>
L van der Walt wrote:
> I have three table:
> Users - Contains username, ID etc...
> Permissions - A permission name and ID
> Link up table - The user.id and permission.id
>
> If a user.id and a permission.id row exists in the linkuptable the user
> have that permission granted.
>
> With the statement below I can see the permissions a user have.
>
> SELECT users.username, permissions.name
> FROM users INNER JOIN linkuptable
> ON (users.id = linkuptable.userid)
> INNER JOIN permissions
> ON (permissions.id = linkuptable.permissionid)
> WHERE users.username = 'DummyUser'
>
> How do I see the permissions that user DON'T have with a fast SQL
> statement.
>
> Thus, a NOT the statement for the above SQL statement
>
> Regards
>
> Lani
>
what you need to do is select all possible permissions and then remove the
permissions that exist. try somthing like:
SELECT permissions.name
FROM permissions.name
WHERE permission.permissionid NOT IN
( SELECT permissions.permissionid
FROM users INNER JOIN linkuptable
ON (users.id = linkuptable.userid)
INNER JOIN permissions
ON (permissions.id = linkuptable.permissionid)
WHERE users.username = 'DummyUser'
)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: stigerikson_nospam_@yahoo.se
Subject: Re: A Not Join
In-Reply-To: <dlta4i$2hvu$1@news.hub.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox