pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herbert Liechti <Herbert.Liechti@thinx.ch>
To: postgres <pgsql-general@postgreSQL.org>
Subject: Re: [GENERAL] sql question
Date: Thu, 18 Nov 1999 13:32:33 +0100
Message-ID: <3833F1E1.861CA6AB@thinx.ch> (raw)
References: <C125682C.007DBA95.00@applications.sip.fr>

Alain.Tesio@sip.fr wrote:

> > >  SELECT * FROM adressGroup
> > >   WHERE Group_Id = 6
> > >     AND EXISTS( SELECT AdrGroup_Id FROM adressGroup ag_alias
> > >                  WHERE adressGroup.AdrGroup_Id = ag_alias.AdrGroup_Id
> > >                  GROUP BY AdrGroup_Id HAVING COUNT(*) = 1);
>
> One last try : your query looks pretty strange, maybe you should design it again
> from scratch :
> if I understand well, you want the rows in adressGroup with :
>
> - Group_Id=6
> - adrGroup_Id being unique
>
> So why not :
>
> SELECT * FROM adressGroup
> WHERE Group_Id = 6
> GROUP BY AdrGroup_Id HAVING COUNT(*)=1

No, when you say group_id = 6 then you have already the adresses which belongs to this
group and the result of the 'group by having' statement is always 1.  That's not the solution. Consider the following situation. 
The user sent a letter to the persons which belongs to the adressgroups 1,2 and 3. 
Now he like to send the same letter to the persons which belongs
to adressgroup 6. But It can be that  persons in group 6 belongs 
either to group 1, 2 or 3. So the user wants only those adresses which belongs to adressgroup 6 and do not count to any other group. That's way I tried 
the statement with the Exists clause.

Greetings Herbie

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herbert Liechti                            E-Mail: Herbert.Liechti@thinx.ch
ThinX networked business services               Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



view thread (71+ messages)  latest in thread

Message-ID: <3833F1E1.861CA6AB@thinx.ch>
Permalink:  ../3833F1E1.861CA6AB@thinx.ch/
Also on:    postgresql.org/message-id/3833F1E1.861CA6AB@thinx.ch

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: Herbert.Liechti@thinx.ch
  Subject: Re: [GENERAL] sql question
  In-Reply-To: <3833F1E1.861CA6AB@thinx.ch>
  References: <C125682C.007DBA95.00@applications.sip.fr> <3833F1E1.861CA6AB@thinx.ch>

* 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