Re: [GENERAL] sql question

From: Herbert Liechti <Herbert(dot)Liechti(at)thinx(dot)ch>
To: postgres <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: [GENERAL] sql question
Date: 1999-11-18 12:32:33
Message-ID: 3833F1E1.861CA6AB@thinx.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alain(dot)Tesio(at)sip(dot)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(dot)Liechti(at)thinx(dot)ch
ThinX networked business services Stahlrain 10, CH-5200 Brugg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 1999-11-18 12:41:38 Book completed through chapter 6
Previous Message The Hermit Hacker 1999-11-18 06:33:25 Projects Database grows ...