SELECT count(*) FROM (SELECT DISTINCT a, b FROM t) AS t2;
should give you what you want.
>> -----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
>> 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?
>> ---------------------------(end of
>> TIP 1: subscribe and unsubscribe commands go to
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
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 Lane||Date: 2001-03-28 16:10:51|
|Subject: Re: counting distinct rows on more than one column |
|Previous:||From: Josh Berkus||Date: 2001-03-28 15:54:05|
|Subject: Re: DELETE FROM fails with error|