I have two tables. The screenshots with the following structure:
- id (bigint)
- originalFilename (string)
- createdAt (Date)
And the second is screenshotSignatures:
- screenshotId (foreign key for screenshots)
- signature (bigint)
So the screenshots table has one to many relation. So now I need to find all duplicates. It means screenshot has exactly the same signatures. I tried to do following:
SELECT os.id, os."originalFilename", array_agg(signature) as signatures from "development".screenshots os
left join development."screenshotSignatures" s on os.id = s."screenshotId"
WHERE GROUP BY os.id, os."originalFilename" ;
and from this query I get the following result: 
So now I need to find out the duplicates somehow, but I don't know to do it. I thought I can do it some how from screenshotSignatures table. As a result it will be nice to have smth like: screenshots (a,b,c) have the same set of signatures. Later I'll need to delete the oldest screenshots. Any ideas? Thank you