pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jerry Sievers <jerry@jerrysievers.com>
To: pgsql-general@postgresql.org
Subject: Re: A Not Join
Date: 01 Nov 2005 21:28:22 -0500
Message-ID: <m34q6v7ph5.fsf@prod01.jerrysievers.com> (raw)
References: <43677B35.6010005@lani.co.za>

L van der Walt <mailing@lani.co.za> writes:

> 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.
> 

Simple.

select permname
from permissions
where permid not in (
	select permid	
from linkage
	where userid = 'dummy'
);

Or... a slick way to get the anti-permission for the whole bunch of
users is to;

cross join the userids with permids and then EXCEPT SELECT from
linkage table to filter out the active permissions.

Have fun!


-- 
-------------------------------------------------------------------------------
Jerry Sievers   305 854-3001 (home)     WWW ECommerce Consultant
                305 321-1144 (mobile	http://www.JerrySievers.com/



view thread (4+ messages)  latest in thread

Message-ID: <m34q6v7ph5.fsf@prod01.jerrysievers.com>
Permalink:  ../m34q6v7ph5.fsf@prod01.jerrysievers.com/
Also on:    postgresql.org/message-id/m34q6v7ph5.fsf@prod01.jerrysievers.com

 · 

reply

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: jerry@jerrysievers.com, pgsql-general@postgresql.org
  Subject: Re: A Not Join
  In-Reply-To: <m34q6v7ph5.fsf@prod01.jerrysievers.com>

* 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