Search Postgresql Archives

Re: COPY from .csv File and Remove Duplicates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>  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.
-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux