X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 66ECF9DCBBD for ; Sat, 10 Dec 2005 21:16:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 81611-05 for ; Sat, 10 Dec 2005 21:16:23 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.195]) by postgresql.org (Postfix) with ESMTP id 6E51A9DCBE1 for ; Sat, 10 Dec 2005 21:16:18 -0400 (AST) Received: by wproxy.gmail.com with SMTP id i34so1207514wra for ; Sat, 10 Dec 2005 17:16:22 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=TkBMWv9N74Ajhni72xDYOdCxBPuc1CI0PHq+i2I+dRV+8/wg6KNYwSkpB4HcDksnwqVIe/Dn0Xa4VQdKyIVVVomMb89FCRvR3r1LxqLI0D1Sg4ecwrIDsB2xhWC+EqyjDGoTCRJ2E54Y3hGm65yeR7tB03ykLuWs1TGVHb1CIJA= Received: by 10.54.142.10 with SMTP id p10mr6562362wrd; Sat, 10 Dec 2005 17:16:22 -0800 (PST) Received: by 10.54.98.6 with HTTP; Sat, 10 Dec 2005 17:16:22 -0800 (PST) Message-ID: Date: Sat, 10 Dec 2005 20:16:22 -0500 From: Jaime Casanova To: =?ISO-8859-1?Q?Havasv=F6lgyi_Ott=F3?= Subject: Re: select count of distinct rows Cc: pgsql-sql@postgresql.org In-Reply-To: <003001c5fded$53a2c5a0$0200a8c0@OTTO> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20051209053849.498E8F0BEC@svr2.postgresql.org> <003001c5fded$53a2c5a0$0200a8c0@OTTO> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.134 required=5 tests=[AWL=0.134] X-Spam-Score: 0.134 X-Spam-Level: X-Archive-Number: 200512/80 X-Sequence-Number: 23622 On 12/10/05, Havasv=F6lgyi Ott=F3 wrote: > Hi, > > I would like to select the count of distinct rows in a table. > > SELECT COUNT(DISTINCT *) FROM mytable; > > This does not work. How can I do it with Postgres? > > Thanks, > Otto > I guess what you need is to know how many times a single row is duplicated so i think what you need is something like this: SELECT fld1, COUNT(DISTINCT fld1) FROM (SELECT ROW(*) as fld1 FROM mytable) AS foo GROUP BY fld1; -- regards, Jaime Casanova (DBA: DataBase Aniquilator ;)