Re: Quick SQL question . . .

From: "Nigel J(dot) Andrews" <nandrews(at)investsystems(dot)co(dot)uk>
To: "Peter E(dot) Chen" <pchen3(at)jhmi(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Quick SQL question . . .
Date: 2002-05-09 23:50:05
Message-ID: Pine.LNX.4.21.0205100042270.2371-100000@ponder.fairway2k.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Is it just me or do the suggestion made look wrong to anyone else?

Anyway, this is the closest to my mind and I think what I think is the mistake
is just a typo. So I would use.

SELECT identno, count(identno)
FROM some_table
GROUP BY identno
HAVING count(identno) > 1

or even

SELECT count(1) FROM (
SELECT count(identno)
FROM some_table
GROUP BY identno
HAVING count(identno) > 1) a

either one of which will return one of more rows if Peter's uniqueness test
fails.

Right, now someone can correct me :)

On Thu, 9 May 2002, Marie G. Tuite wrote:
> Try
>
> select identno, count(identno) from some_table group by identno having
> count(identno) >=1;
>
>
> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org
> [mailto:pgsql-general-owner(at)postgresql(dot)org]On Behalf Of Peter E. Chen
> Sent: Thursday, May 09, 2002 2:39 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: [GENERAL] Quick SQL question . . .
>
>
> 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?
>
> Peter
>

--
Nigel J. Andrews
Director

---
Logictree Systems Limited
Computer Consultants

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Søren Boll Overgaard 2002-05-09 23:52:09 Re: trouble with (lack of) indexing
Previous Message Tom Lane 2002-05-09 23:38:06 Re: trouble with (lack of) indexing