From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | Rich Shepard <rshepard(at)appl-ecosys(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: COPY from .csv File and Remove Duplicates |
Date: | 2011-08-12 16:10:29 |
Message-ID: | 6CA55C4C-D5C4-43DE-9B35-99C2D6622E4D@yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> A pointer to the appropriate syntax for retrieving the entire row when
> count(loc_name, sample_date, param) > 1 would be much appreciated.
>
> Rich
>
Select *
From table
Natural Inner join (
SELECT loc_name, sample_date, param, Count(*) as duplicate_count
FROM table
Group by loc_name, sample_date, param
) grouped
Where duplicate_count > 1
;
You first group and count on the candidate key and then effectively self-joint that result back onto the original table. natural join is short-hand for cases where the two joining table use the same name for semantically identical field. Much easier than saying "t1.field1 = t2.field1 AND t1.field2 = t2.field2 AND etc..."
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Raymond O'Donnell | 2011-08-12 16:22:31 | Re: Functions returning setof record -- can I use a table type as my return type hint? |
Previous Message | George MacKerron | 2011-08-12 16:04:50 | Functions returning setof record -- can I use a table type as my return type hint? |