Re: How to find not unique rows in a table? - Mailing list pgsql-general

From hubert depesz lubaczewski
Subject Re: How to find not unique rows in a table?
Date
Msg-id 20081008121546.GA31190@depesz.com
Whole thread Raw
In response to Re: How to find not unique rows in a table?  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-general
On Wed, Oct 08, 2008 at 01:36:37PM +0200, A. Kretschmer wrote:
> test=*# select * from dup;
>  a | b
> ---+---
>  1 | 1
>  1 | 2
>  2 | 1
>  1 | 1
>  3 | 3
>  3 | 3
> (6 rows)
>
> test=*# select * from dup where (ctid,a,b) not in (select distinct on (a,b) ctid,* from dup);
>  a | b
> ---+---
>  1 | 1
>  3 | 3
> (2 rows)

another approach:
select a,b from dup group by a,b having count(*) > 1;

depesz

--
Linkedin: http://www.linkedin.com/in/depesz  /  blog: http://www.depesz.com/
jid/gtalk: depesz@depesz.com / aim:depeszhdl / skype:depesz_hdl / gg:6749007

pgsql-general by date:

Previous
From: Michelle Konzack
Date:
Subject: Re: how to use pam-pgsql
Next
From: Tom Lane
Date:
Subject: Re: Stats collector eats my CPU