Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 93536 invoked from network); 28 Aug 2005 13:57:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Aug 2005 13:57:09 -0000 Received: (qmail 63462 invoked by uid 500); 28 Aug 2005 13:57:08 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 63410 invoked by uid 500); 28 Aug 2005 13:57:07 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Development" Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 63397 invoked by uid 99); 28 Aug 2005 13:57:07 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=SPF_FAIL X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 28 Aug 2005 06:57:06 -0700 Received: from ajax.apache.org (ajax.apache.org [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 2E6AD13E for ; Sun, 28 Aug 2005 15:57:05 +0200 (CEST) Message-ID: <1507986360.1125237425188.JavaMail.jira@ajax.apache.org> Date: Sun, 28 Aug 2005 15:57:05 +0200 (CEST) From: "Knut Anders Hatlen (JIRA)" To: derby-dev@db.apache.org Subject: [jira] Updated: (DERBY-504) SELECT DISTINCT returns duplicates when selecting from subselects In-Reply-To: <711144378.1123837734103.JavaMail.jira@ajax.apache.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N [ http://issues.apache.org/jira/browse/DERBY-504?page=all ] Knut Anders Hatlen updated DERBY-504: ------------------------------------- Attachment: (was: DERBY-504.diff) > SELECT DISTINCT returns duplicates when selecting from subselects > ----------------------------------------------------------------- > > Key: DERBY-504 > URL: http://issues.apache.org/jira/browse/DERBY-504 > Project: Derby > Type: Bug > Components: SQL > Versions: 10.2.0.0 > Environment: Latest development sources (SVN revision 232227), Sun JDK 1.5, Solaris/x86 > Reporter: Knut Anders Hatlen > Assignee: Knut Anders Hatlen > Priority: Minor > > When one performs a select distinct on a table generated by a subselect, there sometimes are duplicates in the result. The following example shows the problem: > ij> CREATE TABLE names (id INT PRIMARY KEY, name VARCHAR(10)); > 0 rows inserted/updated/deleted > ij> INSERT INTO names (id, name) VALUES > (1, 'Anna'), (2, 'Ben'), (3, 'Carl'), > (4, 'Carl'), (5, 'Ben'), (6, 'Anna'); > 6 rows inserted/updated/deleted > ij> SELECT DISTINCT(name) FROM (SELECT name, id FROM names) AS n; > NAME > ---------- > Anna > Ben > Carl > Carl > Ben > Anna > Six names are returned, although only three names should have been returned. > When the result is explicitly sorted (using ORDER BY) or the id column is removed from the subselect, the query returns three names as expected: > ij> SELECT DISTINCT(name) FROM (SELECT name, id FROM names) AS n ORDER BY name; > NAME > ---------- > Anna > Ben > Carl > 3 rows selected > ij> SELECT DISTINCT(name) FROM (SELECT name FROM names) AS n; > NAME > ---------- > Anna > Ben > Carl > 3 rows selected -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira