X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 775B2329E87 for ; Mon, 20 Sep 2004 17:43:43 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22009-09 for ; Mon, 20 Sep 2004 16:43:38 +0000 (GMT) Received: from p15124592.pureserver.info (p15124592.pureserver.info [217.160.181.164]) by svr1.postgresql.org (Postfix) with ESMTP id 8784D329E8E for ; Mon, 20 Sep 2004 17:43:36 +0100 (BST) Received: from localhost (localhost [127.0.0.1]) by p15124592.pureserver.info (Postfix) with ESMTP id 0A16617AF7; Mon, 20 Sep 2004 18:43:32 +0200 (CEST) Received: from kniso.homeip.net (pD95FFC80.dip.t-dialin.net [217.95.252.128]) by p15124592.pureserver.info (Postfix) with ESMTP id E8E7D17AD5 for ; Mon, 20 Sep 2004 18:43:30 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by kniso.homeip.net (Postfix) with ESMTP id 5FA80D7995 for ; Mon, 20 Sep 2004 18:43:19 +0200 (CEST) Received: from kniso.homeip.net ([127.0.0.1]) by localhost (server.kniso.homeip.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 23349-08 for ; Mon, 20 Sep 2004 18:43:15 +0200 (CEST) Received: from [192.168.100.110] (nexus.kniso.homeip.net [192.168.100.110]) by kniso.homeip.net (Postfix) with ESMTP id DD50AD7994 for ; Mon, 20 Sep 2004 18:43:14 +0200 (CEST) Message-ID: <414F08FD.3080200@mk-os.de> Date: Mon, 20 Sep 2004 18:44:45 +0200 From: Martin Knipper User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-AT; rv:1.7) Gecko/20040616 X-Accept-Language: de, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: COUNT(*) to find records which have a certain number of References: <414F02FF.8000603@numerixtechnology.de> In-Reply-To: <414F02FF.8000603@numerixtechnology.de> X-Enigmail-Version: 0.85.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian/SARGE) at kniso.homeip.net X-Virus-Scanned: by AMaViS at MK-OS X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/222 X-Sequence-Number: 19068 Am 20.09.2004 18:19 schrieb T E Schmitz: > I figured it eventually. (The only thing I don't know is where to put > the ORDER BY.) > > >>I want to select only those BRAND/MODEL combinations, where the MODEL >>has more than one TYPE, but only where one of those has TYPE_NAME='xyz'. >>I am not interested in MODELs with multiple TYPEs where none of them are >>called 'xyz'. > > Try this: select b.brand_name,m.model_name,count(*) from model m inner join brand b on m.brand_fk=b.brand_pk inner join type t on m.model_pk=t.model_fk where t.type_name='xyz' group by b.brand_name,m.model_name having count(m.model_name)>0; Greetings, Martin -- Martin Knipper www : http://www.mk-os.de Mail : knipper@mk-os.de