Re: A select DISTINCT query?

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: phil(at)pricom(dot)com(dot)au
Cc: "Tino Wildenhain" <tino(at)wildenhain(dot)de>, pgsql-general(at)postgresql(dot)org
Subject: Re: A select DISTINCT query?
Date: 2008-01-27 16:38:23
Message-ID: 162867790801270838v3af77af4le121aa133bc852f4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 27/01/2008, Phil Rhoades <phil(at)pricom(dot)com(dot)au> wrote:
> Tino,
>
>
> On Sun, 2008-01-27 at 15:16 +0100, Tino Wildenhain wrote:
> > Phil Rhoades wrote:
> > > People,
> > >
> > > I want to select from a table ONLY unique records ie if a column has
> > > values:
> > >
> > > 1
> > > 2
> > > 3
> > > 3
> > > 4
> > > 5
> > >
> > > I want ONLY these records returned:
> > >
> > > 1
> > > 2
> > > 4
> > > 5
> >
> >
> > SELECT count(*) as cnt,a,b,c FORM yourtable
> > GROUP BY a,b,c
> > HAVING cnt=1
> >
> > should do.
>
>
> I get:
>
> SELECT count(*) as cnt, name FRoM tst GROUP BY name HAVING cnt = 1 ;
> ERROR: column "cnt" does not exist
> LINE 1: ...ount(*) as cnt, name FRoM tst GROUP BY name HAVING cnt = 1 ;
> ^
>
select count(*) as cnt, name from tst group by name having count(*) = 1

> Thanks,
>
> Phil.
> --
> Philip Rhoades
>
> Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)
> GPO Box 3411
> Sydney NSW 2001
> Australia
> Fax: +61:(0)2-8221-9599
> E-mail: phil(at)pricom(dot)com(dot)au
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Phil Rhoades 2008-01-27 16:41:12 Re: A select DISTINCT query?
Previous Message hubert depesz lubaczewski 2008-01-27 16:35:47 Re: A select DISTINCT query?