pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ben Morrow <ben@morrow.me.uk>
To: junaidmalik14@gmail.com
To: pgsql-sql@postgresql.org
Subject: Re: count function alternative in postgres
Date: Tue, 6 Apr 2010 19:47:14 +0100
Message-ID: <20100406184714.GA3290@osiris.mauzo.dyndns.org> (raw)
In-Reply-To: <28126792.post@talk.nabble.com>

Quoth junaidmalik14@gmail.com (junaidmalik14):
> 
> Is there any alternative of mysql function COUNT(DISTINCT expr,[expr...]) in
> postgres. We get error if we 
> 
> write count like this count(distinct profile.id, profile.name, profile.age)
> but it works well in mysql.

Pg does support COUNT(DISTINCT ), but only for a single column. The best
I can come up with for multiple columns is

    select count(distinct profile.tuple) from
        (select (id, name, age) as tuple from profile)
            as profile;

or alternatively

    select count(*) from
        (select distinct (id, name, age) as tuple from profile)
            as profile;

Ben




view thread (5+ messages)  latest in thread

Message-ID: <20100406184714.GA3290@osiris.mauzo.dyndns.org>
Permalink:  ../20100406184714.GA3290@osiris.mauzo.dyndns.org/
Also on:    postgresql.org/message-id/20100406184714.GA3290@osiris.mauzo.dyndns.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ben@morrow.me.uk, junaidmalik14@gmail.com
  Subject: Re: count function alternative in postgres
  In-Reply-To: <20100406184714.GA3290@osiris.mauzo.dyndns.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox