Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 36164 invoked from network); 30 Jun 2008 07:08:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Jun 2008 07:08:51 -0000 Received: (qmail 70636 invoked by uid 500); 30 Jun 2008 07:08:51 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 70609 invoked by uid 500); 30 Jun 2008 07:08:51 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 70598 invoked by uid 99); 30 Jun 2008 07:08:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Jun 2008 00:08:51 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [63.246.20.101] (HELO mail.sixfriedrice.com) (63.246.20.101) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Jun 2008 07:08:01 +0000 Received: (qmail 9494 invoked by uid 89); 30 Jun 2008 07:07:21 -0000 Received: by simscan 1.4.0 ppid: 9488, pid: 9490, t: 0.1890s scanners: regex: 1.4.0 clamav: 0.91.2/m:33/d:989 Received: from unknown (HELO ?10.0.1.199?) (geoff@sixfriedrice.com@68.3.73.169) by mail.sixfriedrice.com with ESMTPA; 30 Jun 2008 07:07:21 -0000 Message-Id: <3DD376AD-B003-462A-81B2-1688E74793C2@sixfriedrice.com> From: Six Fried Rice To: Derby Discussion Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v924) Subject: Concatenating text from multiple rows Date: Mon, 30 Jun 2008 00:07:20 -0700 X-Mailer: Apple Mail (2.924) X-Virus-Checked: Checked by ClamAV on apache.org I have a table "CUSTOM_FUNCTION" with an ID, and another table "CUSTOM_FUNCTION_PARAMETER" with a foreign key "ID_CUSTOM_FUNCTION" such that each CUSTOM_FUNCTION record has 0 or more associated CUSTOM_FUNCTION_PARAMETER records. In one situation, it would be exceptionally handy to concatenate all associated values from a VARCHAR column in the CUSTOM_FUNCTION_PARAMETER table into a single value in a result set with one row per CUSTOM_FUNCTION. For instance, suppose I have: CUSTOM_FUNCTION.ID = 1 CUSTOM_FUNCTION.NAME = "Volume" CUSTOM_FUNCTION_PARAMETER.ID_CUSTOM_FUNCTION = 1 CUSTOM_FUNCTION_PARAMETER.NAME = "length" CUSTOM_FUNCTION_PARAMETER.ID_CUSTOM_FUNCTION = 1 CUSTOM_FUNCTION_PARAMETER.NAME = "width" CUSTOM_FUNCTION_PARAMETER.ID_CUSTOM_FUNCTION = 1 CUSTOM_FUNCTION_PARAMETER.NAME = "height" I would like a single SQL query that returns a single row like this: NAME: Volume PARAMS: length; width; height Where the "params" result column is a VARCHAR with all three parameter names concatenated, with semicolon's in between. In MySQL, I would accomplish this with the odd-but-handy GROUP_CONCAT function, along these lines: select F.NAME as NAME, GROUP_CONCAT(P.NAME, "; ") as PARAMS from CUSTOM_FUNCTION F left join CUSTOM_FUNCTION_PARAMETER P on P.ID_CUSTOM_FUNCTION = F.ID group by F.ID I know that isn't standard, but I'm wondering if there is any clever approach in Derby to accomplish the same thing. I've been trying to dream something up, but with no success so far. Of course I know I can get the same effect by processing the result set on the Java side, but for various reasons, it would be much more convenient in this case to let Derby do it for me. Any ideas would be appreciated. Thanks, Geoff