Re: How to find not unique rows in a table?

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to find not unique rows in a table?
Date: 2008-10-08 12:15:46
Message-ID: 20081008121546.GA31190@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)depesz(dot)com / aim:depeszhdl / skype:depesz_hdl / gg:6749007

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dejan Dimic 2008-10-08 12:57:32 Re: how to use pam-pgsql
Previous Message A. Kretschmer 2008-10-08 11:36:37 Re: How to find not unique rows in a table?