Issue Details (XML | Word | Printable)

Key: DERBY-504
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Knut Anders Hatlen
Reporter: Knut Anders Hatlen
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

SELECT DISTINCT returns duplicates when selecting from subselects

Created: 12/Aug/05 06:07 PM   Updated: 11/Jan/07 09:49 AM
Return to search
Component/s: SQL
Affects Version/s: 10.1.2.1
Fix Version/s: 10.1.2.1, 10.2.1.6

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works DERBY-504-10.1-unix.diff 2005-09-07 06:27 PM Knut Anders Hatlen 64 kB
File Licensed for inclusion in ASF works DERBY-504-10.1-windows.diff 2005-09-07 06:27 PM Knut Anders Hatlen 65 kB
Text File Licensed for inclusion in ASF works DERBY-504-10.1.stat 2005-09-07 06:27 PM Knut Anders Hatlen 1.0 kB
File Licensed for inclusion in ASF works DERBY-504-cleanup.diff 2005-09-07 06:17 PM Knut Anders Hatlen 2 kB
Text File Licensed for inclusion in ASF works DERBY-504-cleanup.stat 2005-09-07 06:17 PM Knut Anders Hatlen 0.1 kB
File Licensed for inclusion in ASF works DERBY-504.diff 2005-08-28 11:10 PM Knut Anders Hatlen 27 kB
File Licensed for inclusion in ASF works DERBY-504.stat 2005-08-28 11:10 PM Knut Anders Hatlen 0.7 kB
Text File Licensed for inclusion in ASF works DERBY-504_b.diff 2005-08-31 10:16 AM Myrna van Lunteren 65 kB
Text File Licensed for inclusion in ASF works DERBY-504_b.stat 2005-08-31 10:16 AM Myrna van Lunteren 0.9 kB
File Licensed for inclusion in ASF works DERBY-504_c-CRLF.diff 2005-09-02 01:38 AM Knut Anders Hatlen 64 kB
File Licensed for inclusion in ASF works DERBY-504_c-CRLF.diff 2005-09-02 01:35 AM Knut Anders Hatlen 64 kB
File Licensed for inclusion in ASF works DERBY-504_c.diff 2005-09-01 09:19 PM Knut Anders Hatlen 63 kB
Text File Licensed for inclusion in ASF works DERBY-504_c.stat 2005-09-01 09:19 PM Knut Anders Hatlen 0.9 kB
Environment: Latest development sources (SVN revision 232227), Sun JDK 1.5, Solaris/x86
Issue Links:
Dependants
 

Resolution Date: 11/Jan/07 09:49 AM


 Description  « Hide
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

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Knut Anders Hatlen made changes - 17/Aug/05 02:19 AM
Field Original Value New Value
Assignee Knut Anders Hatlen [ knutanders ]
Knut Anders Hatlen made changes - 19/Aug/05 01:30 AM
Status Open [ 1 ] In Progress [ 3 ]
Knut Anders Hatlen made changes - 19/Aug/05 01:33 AM
Attachment DERBY-504.distinct.diff [ 12311832 ]
Knut Anders Hatlen made changes - 19/Aug/05 11:56 PM
Link This issue blocks DERBY-519 [ DERBY-519 ]
Knut Anders Hatlen made changes - 26/Aug/05 06:49 PM
Attachment DERBY-504.distinct.diff [ 12311832 ]
Knut Anders Hatlen made changes - 26/Aug/05 08:40 PM
Attachment DERBY-504.diff [ 12312000 ]
Knut Anders Hatlen made changes - 28/Aug/05 10:56 PM
Attachment DERBY-504.diff [ 12312000 ]
Knut Anders Hatlen made changes - 28/Aug/05 11:10 PM
Attachment DERBY-504.stat [ 12312054 ]
Attachment DERBY-504.diff [ 12312053 ]
Myrna van Lunteren made changes - 31/Aug/05 10:16 AM
Attachment DERBY-504_b.diff [ 12312097 ]
Attachment DERBY-504_b.stat [ 12312098 ]
Knut Anders Hatlen made changes - 01/Sep/05 09:19 PM
Attachment DERBY-504_c.diff [ 12312126 ]
Attachment DERBY-504_c.stat [ 12312127 ]
Knut Anders Hatlen made changes - 02/Sep/05 01:35 AM
Attachment DERBY-504_c-CRLF.diff [ 12312138 ]
Knut Anders Hatlen made changes - 02/Sep/05 01:43 AM
Attachment DERBY-504_c-CRLF.diff [ 12312139 ]
Knut Anders Hatlen made changes - 07/Sep/05 06:17 PM
Attachment DERBY-504-cleanup.diff [ 12312762 ]
Attachment DERBY-504-cleanup.stat [ 12312763 ]
Knut Anders Hatlen made changes - 07/Sep/05 06:27 PM
Attachment DERBY-504-10.1.stat [ 12312766 ]
Attachment DERBY-504-10.1-windows.diff [ 12312765 ]
Attachment DERBY-504-10.1-unix.diff [ 12312764 ]
Knut Anders Hatlen made changes - 13/Sep/05 03:37 PM
Fix Version/s 10.2.0.0 [ 11187 ]
Status In Progress [ 3 ] Closed [ 6 ]
Resolution Fixed [ 1 ]
Knut Anders Hatlen made changes - 20/Sep/05 04:08 PM
Resolution Fixed [ 1 ]
Status Closed [ 6 ] Reopened [ 4 ]
Knut Anders Hatlen made changes - 20/Sep/05 04:09 PM
Affects Version/s 10.2.0.0 [ 11187 ]
Fix Version/s 10.2.0.0 [ 11187 ]
Fix Version/s 10.1.2.0 [ 12310270 ]
Affects Version/s 10.1.2.0 [ 12310270 ]
Knut Anders Hatlen made changes - 20/Sep/05 11:17 PM
Fix Version/s 10.2.0.0 [ 11187 ]
Knut Anders Hatlen made changes - 07/Oct/05 04:02 PM
Fix Version/s 10.1.1.2 [ 12310353 ]
Resolution Fixed [ 1 ]
Status Reopened [ 4 ] Closed [ 6 ]
Knut Anders Hatlen made changes - 11/Jan/07 09:46 AM
Status Closed [ 6 ] Reopened [ 4 ]
Resolution Fixed [ 1 ]
Knut Anders Hatlen made changes - 11/Jan/07 09:49 AM
Resolution Fixed [ 1 ]
Status Reopened [ 4 ] Closed [ 6 ]