Re: Quick SQL question . . .

From: Herbert Liechti <Herbert(dot)Liechti(at)thinx(dot)ch>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Quick SQL question . . .
Date: 2002-05-09 20:06:17
Message-ID: 3CDAD6B9.8050403@thinx.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Thu, 9 May 2002, Peter E. Chen wrote:

> Can anyone tell me what is the easiest way for me to tell if a column is
> unique or not? I tried using DISTINCT ON and COUNT together in a SELECT
> statement, but I can't seem to get the query to work:
>
> SELECT DISTINCT ON (identno) count(identno) FROM some_table;
>
> I was trying to figure out if the # of unique entries for a particular
> column is equal to the # of total entries for that column.
>
> Any suggestions?

SELECT identno, count(*) FROM some_table
GROUP BY 1 HAVING COUNT(*) = 1;

Regards Herbie
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Herbert Liechti http://www.thinx.ch
ThinX networked business services Adlergasse 5, CH-4500 Solothurn
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Browse pgsql-general by date

  From Date Subject
Next Message Søren Boll Overgaard 2002-05-09 21:25:34 trouble with (lack of) indexing
Previous Message Marie G. Tuite 2002-05-09 20:04:33 Re: Quick SQL question . . .