Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 29301475E64 for ; Tue, 6 Aug 2002 04:03:24 -0400 (EDT) Received: from mta02-svc.ntlworld.com (mta02-svc.ntlworld.com [62.253.162.42]) by postgresql.org (Postfix) with ESMTP id 4E57F475E60 for ; Tue, 6 Aug 2002 04:03:23 -0400 (EDT) Received: from Wilbur ([80.2.246.217]) by mta02-svc.ntlworld.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with SMTP id <20020806080324.YFCX290.mta02-svc.ntlworld.com@Wilbur> for ; Tue, 6 Aug 2002 09:03:24 +0100 Message-ID: <005201c23d1f$bb4f6ba0$0500a8c0@Wilbur> From: "Julian Scarfe" To: Subject: Concatenate aggregate? Date: Tue, 6 Aug 2002 09:03:21 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/80 X-Sequence-Number: 8926 I'd like to concatenate text from one field that has been returned by a grouped query. e.g. create table test (id int, thetext text); CREATE playj=> insert into test values (1, 'Hello number 1'); INSERT 697997 1 playj=> insert into test values (2, 'Hello number 2'); INSERT 697998 1 playj=> insert into test values (1, 'Hello again number 1'); INSERT 697999 1 playj=> select * from test; id | thetext ----+---------------------- 1 | Hello number 1 2 | Hello number 2 1 | Hello again number 1 (3 rows) I can do: playj=> select id, max(thetext) from test group by id; id | max ----+---------------- 1 | Hello number 1 2 | Hello number 2 (2 rows) But what I'd like to do is something like: playj=> select id, concat(thetext, ' -- ') from test group by id; id | concat ----+---------------- 1 | Hello number 1 -- Hello again number 1 2 | Hello number 2 (2 rows) [Ordering is unimportant here.] Any pointers to useful starting points please? Thanks Julian Scarfe