
|
If you were logged in you would be able to see more operations.
|
|
|
|
File Attachments:
|
|
|
Environment:
|
Latest development sources (SVN revision 232227), Sun JDK 1.5, Solaris/x86
|
|
Issue Links:
|
Dependants
|
|
|
|
This issue blocks:
|
|
DERBY-519
GROUP BY test depends on incorrect behaviour
|
|
|
|
|
|
|
| Resolution Date: |
11/Jan/07 09:49 AM
|
|
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
|
|
Description
|
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 |
Show » |
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:33 AM
|
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 - 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 - 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
]
|
|