Re: unique fields

From: "Oliveiros d'Azevedo Cristina" <oliveiros(dot)cristina(at)marktest(dot)pt>
To: "Adrian Johnson" <oriolebaltimore(at)gmail(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: unique fields
Date: 2010-09-23 10:01:39
Message-ID: E2CC03D50211418EAD9A241056A81DD1@marktestcr.marktest.pt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Howdy, Adrian

Dunno if this is exactly what you want

SELECT *
FROM
(
SELECT chr,cfrom,cto,count(*) as numberOfDuplicates
FROM t_fairly_large_table
GROUP BY chr,cfrom,cto
) x
NATURAL JOIN t_fairly_large_table y
WHERE numberOfDuplicates > 1

The idea of this (untested) query
is to produce something like

chr| cfrom | cto | numberOfDuplicates| sample_id
c2 19 20 3 1
c2 19 20 3 2
c2 19 20 3 3
c5 10 11 2 1
c5 10 11 2 3

Can this be what you need?

Best,
Oliver

----- Original Message -----
From: "Adrian Johnson" <oriolebaltimore(at)gmail(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Sent: Thursday, September 23, 2010 4:30 AM
Subject: [SQL] unique fields

> hi:
>
> I have a fairly large table.
>
> sample_id | chr | cfrom | cto |
> -------------------------------------------
> 1 c2 19 20
> 2 c2 19 20
> 3 c2 19 20
> 1 c5 10 11
> 3 c5 10 11
>
>
> (25,000 rows)
>
> I want to find out how many duplications are there for chr, cfrom and cto
>
> a. c2,19,20 are common to samples 1,2 and 3.
>
> since there will be many instances like that, do I have to loop over
> entire rows and find common chr, cfrom and c2 and ouput with
> sample_id.
> how can I do that.
>
> thanks
> adrian
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Schmitz 2010-09-23 10:53:13 Re: HowTo divide streetname from house-nr ?
Previous Message Sergey Konoplev 2010-09-23 07:33:22 Re: unique fields