Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 5A93D28C7B for ; Sat, 19 May 2012 16:04:52 -0300 (ADT) Received: from mailout-de.gmx.net ([213.165.64.22]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1SVoxO-0001TS-UX for pgsql-sql@postgresql.org; Sat, 19 May 2012 19:04:51 +0000 Received: (qmail invoked by alias); 19 May 2012 19:04:37 -0000 Received: from mue-88-130-14-029.dsl.tropolys.de (EHLO [192.168.1.113]) [88.130.14.29] by mail.gmx.net (mp072) with SMTP; 19 May 2012 21:04:37 +0200 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX1+ZZepWKKWZLfYnbeewO/FkhmKSpgl7LgI+mNJVG6 vuf/IeiVcmkUEP Message-ID: <4FB7EEC6.1030004@gmx.net> Date: Sat, 19 May 2012 21:04:38 +0200 From: Andreas User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: "pgsql-sql@postgresql.org" Subject: Need help in grouping records Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/52 X-Sequence-Number: 36600 Hi, I'm trying to fight against double entries in tables. I got as far as I can find similar records with trigram string matching. If I do this with a table compared to itself I get something like this: id_a, id_b 3, 5 3, 7 5, 3 5, 7 7, 3 7, 5 11, 13 13, 11 so the records with the IDs 3, 5, 7 and 11, 13 are similar enough to form a group. How would I get a list of record-IDs with a group-ID like this record_id, group_id 3, 1 5, 1 7, 1 11, 2 13, 2 Is there a way to get this by SQL ?