Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 70717 invoked from network); 18 Aug 2006 07:31:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 Aug 2006 07:31:31 -0000 Received: (qmail 49756 invoked by uid 500); 18 Aug 2006 07:31:30 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 49597 invoked by uid 500); 18 Aug 2006 07:31:29 -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 49586 invoked by uid 99); 18 Aug 2006 07:31:29 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Aug 2006 00:31:29 -0700 X-ASF-Spam-Status: No, hits=0.6 required=10.0 tests=NO_REAL_NAME,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [192.18.1.36] (HELO gmpea-pix-1.sun.com) (192.18.1.36) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Aug 2006 00:31:27 -0700 Received: from d1-emea-09.sun.com (d1-emea-09.sun.com [192.18.2.119] (may be forged)) by gmpea-pix-1.sun.com (8.13.6+Sun/8.12.9) with ESMTP id k7I7V31G028343 for ; Fri, 18 Aug 2006 08:31:05 +0100 (BST) Received: from conversion-daemon.d1-emea-09.sun.com by d1-emea-09.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) id <0J4600H01NIGY000@d1-emea-09.sun.com> (original mail from Dyre.Tjeldvoll@Sun.COM) for derby-user@db.apache.org; Fri, 18 Aug 2006 08:31:03 +0100 (BST) Received: from khepri29.sun.com ([129.159.112.241]) by d1-emea-09.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPSA id <0J46006E6NJP9E00@d1-emea-09.sun.com> for derby-user@db.apache.org; Fri, 18 Aug 2006 08:31:03 +0100 (BST) Date: Fri, 18 Aug 2006 09:31:00 +0200 From: Dyre.Tjeldvoll@Sun.COM Subject: Re: LEFT JOIN with a subquery not working in Derby? In-reply-to: <96787933F10FC7419E66FF094F105F091D71@snowball2005.maner.local> Sender: Dyre.Tjeldvoll@Sun.COM To: Derby Discussion Message-id: MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT References: <96787933F10FC7419E66FF094F105F091D71@snowball2005.maner.local> User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (usg-unix-v) X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N "Halit M. Maner" writes: > The statement below has been working fine in Cloudscape 5.1 but it is not working in Derby (we are using 10.1.2.4). > > ij> SELECT * FROM admapphdr LEFT JOIN admappdtl ON (aah_id=aad_aah_id AND > aad_seq_num = (SELECT MAX(a2.aad_seq_num) FROM admappdtl a2)); > > It is throwing: > > ERROR 42972: An ON clause associated with a JOIN operator is not valid. > > It works fine if we remove the SELECT MAX (but we need it!)... > > admapphdr is a header table with an INTEGER id. > admappdtl is admapphdr's detail table with the same id plus a sequence number for the various detail rows... > > Is this a limitation of Derby or are we overlooking something? Sorry about the late reply. You probably have found a workaround by now. Couldn't you just perform the 'select MAX' first, and insert the value in your join condition? (A pain, I know...) In the general case where the sub-query returns multiple rows, you could create a view of the sub-query, and then join the two tables with this view in a three-way join. -- dt However, experience shows that for many people and many applications a dose of paranoia is reasonable - Bjarne Stroustrup