Received: from outthere.thinx.ch (outthere.thinx.ch [194.158.233.34]) by hub.org (8.9.3/8.9.3) with ESMTP id IAA27621 for ; Thu, 18 Nov 1999 08:02:18 -0500 (EST) (envelope-from Herbert.Liechti@thinx.ch) Received: from venus.net.thinx.ch (root@dyna-ol-22.dial.eunet.ch [193.72.192.245]) by outthere.thinx.ch (8.9.2/8.9.2) with ESMTP id OAA17335 for ; Thu, 18 Nov 1999 14:02:01 +0100 (CET) Received: from thinx.ch (herbie@tobi.net.thinx.ch [192.168.0.9]) by venus.net.thinx.ch (8.8.8/8.8.8) with ESMTP id OAA01439 for ; Thu, 18 Nov 1999 14:02:16 +0100 Sender: herbie@eunet.ch Message-ID: <3833F1E1.861CA6AB@thinx.ch> Date: Thu, 18 Nov 1999 13:32:33 +0100 From: Herbert Liechti Organization: ThinX networked business services X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.5 i686) X-Accept-Language: en MIME-Version: 1.0 To: postgres Subject: Re: [GENERAL] sql question References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~