Re: compare two rows

From: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>
To: Ben Kim <bkim(at)tamu(dot)edu>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: compare two rows
Date: 2010-10-12 22:17:23
Message-ID: AANLkTimosiCc=95z_sHOUM2-rt5wGh23wTe_R8kC4k4_@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Tue, Oct 12, 2010 at 3:10 PM, Ben Kim <bkim(at)tamu(dot)edu> wrote:

> create table test_dup (id serial primary key, val text);
> insert into test_dup(val)values('some text');
> insert into test_dup(val)values('some texta');
>
> select * from test_dup;
>  id |    val
> ----+------------
>  1 | some text
>  2 | some texta

SELECT Array_agg( id ) AS duplicate_ids, val
FROM test_dup
GROUP BY val
HAVING COUNT(*) > 1;

SELECT T1.id, T2.id, T.val
FROM test_dup AS T1
INNER JOIN test_dup AS T2
USING ( val );

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Kevin Grittner 2010-10-12 22:30:28 Re: compare two rows
Previous Message Ben Kim 2010-10-12 22:10:55 Re: compare two rows