Skip site navigation (1) Skip section navigation (2)

RE: counting distinct rows on more than one column

From: Michael Ansley <Michael(dot)Ansley(at)intec-telecom-systems(dot)com>
To: "'Dirk Lutzebaeck'" <lutzeb(at)aeccom(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: RE: counting distinct rows on more than one column
Date: 2001-03-28 15:58:13
Message-ID: 7F124BC48D56D411812500D0B747251480F4F1@FILESERVER002 (view raw or flat)
Thread:
Lists: pgsql-sql
SELECT count(*) FROM (SELECT DISTINCT a, b FROM t) AS t2;

should give you what you want.


MikeA


>> -----Original Message-----
>> From: Dirk Lutzebaeck [mailto:lutzeb(at)aeccom(dot)com]
>> Sent: 28 March 2001 16:11
>> To: pgsql-sql(at)postgresql(dot)org
>> Subject: [SQL] counting distinct rows on more than one column
>> 
>> 
>> 
>> Hi,
>> 
>> on 7.0.3 want to COUNT
>> 
>>   SELECT DISTINCT a,b FROM t;
>> 
>> I can't find a solution because any combination with
>> count with more than one column gives syntax errors.
>> 
>> One solution would be to set a view:
>> 
>> CREATE VIEW v AS SELECT DISTINCT a,b FROM t;
>> 
>> and then
>> 
>> SELECT count(a) FROM v
>> 
>> but views don't support distinct in v7.0.3
>> 
>> Ok I could use a temporary table but my select distinct tends to give
>> large results.
>> 
>> Any clues?
>> 
>> Dirk
>> 
>> 
>> 
>> ---------------------------(end of 
>> broadcast)---------------------------
>> TIP 1: subscribe and unsubscribe commands go to 
>> majordomo(at)postgresql(dot)org
>> 


_________________________________________________________________________
This e-mail and any attachments are confidential and may also be privileged and/or copyright 
material of Intec Telecom Systems PLC (or its affiliated companies).  If you are not an 
intended or authorised recipient of this e-mail or have received it in error, please delete 
it immediately and notify the sender by e-mail.  In such a case, reading, reproducing, 
printing or further dissemination of this e-mail is strictly prohibited and may be unlawful. 
Intec Telecom Systems PLC. does not represent or warrant that an attachment hereto is free 
from computer viruses or other defects. The opinions expressed in this e-mail and any 
attachments may be those of the author and are not necessarily those of Intec Telecom 
Systems PLC. 

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses. 
__________________________________________________________________________

pgsql-sql by date

Next:From: Tom LaneDate: 2001-03-28 16:10:51
Subject: Re: counting distinct rows on more than one column
Previous:From: Josh BerkusDate: 2001-03-28 15:54:05
Subject: Re: DELETE FROM fails with error

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group