How can I link duplicate records in PostrgreSQL? I've found them with:
SELECT * FROM (
SELECT id, import_id, name,
ROW_NUMBER() OVER(PARTITION BY address ORDER BY name asc) AS Row
FROM companies
) dups
where
dups.Row > 1 ORDER BY dups.name;
See sample code and demo at http://sqlfiddle.com/#!15/af016/7/1
I want to add a column to companies called linked_id
, that will be set to the import_id
of the first of each set of duplicate records.