pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Glenn MacGregor <gtm@oracom.com>
To: pgsql-sql@postgresql.org
Subject: Complex query help please
Date: Tue, 27 Nov 2001 17:23:25 -0500
Message-ID: <020c01c17792$2176f820$4d00a8c0@catamount> (raw)

Hi All,

I am new to sql and have the need for a complex query.  I have figured out how to do it in two queries but I would like to get it down to one.  I will give you my queries and hopefully some can give me some assistance.
Thanks

Query 1:
create temp table ttable1 as select xpressuser.username, xpressvimpermission.commandaccess, xpressvimpermission.eventaccess from xpressvim left join xpressvimpermission using (vimid) left join xpressgroup using (groupid) left join xpressuser using (groupid) where xpressvim.vimname = 'testvim2';

creates a temp table.

Query 2:
select * from ttable1 union select xpressuser.username, xpressgroup.commandaccess,  xpressgroup.eventaccess from xpressgroup left join xpressuser using (groupid) where xpressuser.username not in (select username from ttable1) and (xpressgroup.commandaccess != 'n' or  xpressgroup.eventaccess != 'f');

So the idea is I have a default set of permissions that users get, these permissions can be overridden on each vim for each group(user).  The first query results in a table which has all the overridden permissions.
The second query results in a table which has all the default permissions unioned with the previous table and not in the previous table.

Is there any way to do this one query or a function?

    Thanks

            Glenn

view thread (2+ messages)  latest in thread

Message-ID: <020c01c17792$2176f820$4d00a8c0@catamount>
Permalink:  ../020c01c17792$2176f820$4d00a8c0@catamount/
Also on:    postgresql.org/message-id/020c01c17792$2176f820$4d00a8c0@catamount

 · 

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: gtm@oracom.com
  Subject: Re: Complex query help please
  In-Reply-To: <020c01c17792$2176f820$4d00a8c0@catamount>

* 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