Re: A Not Join

From: stig erikson <stigerikson_nospam_(at)yahoo(dot)se>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: A Not Join
Date: 2005-11-21 20:16:13
Message-ID: dlta4i$2hvu$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

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'
)

In response to

  • A Not Join at 2005-11-01 14:27:01 from L van der Walt

Browse pgsql-general by date

  From Date Subject
Next Message Chris Kratz 2005-11-21 20:27:33 Rule appears not to fire on insert w/ "except"
Previous Message Florian G. Pflug 2005-11-21 19:50:24 Re: Multi-parameter aggregates.

Browse pgsql-sql by date

  From Date Subject
Next Message george young 2005-11-21 21:00:16 tid_le comparison for tuple id (ctid) values?
Previous Message Tom Lane 2005-11-21 15:03:45 Re: max() unexpected type conversion