提交 0690ef9a authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

DISTINCT does not work with ORDER BY in some queries

上级 e8cf7005
......@@ -835,7 +835,7 @@ public class Select extends Query {
}
if (orderList != null) {
initOrder(session, expressions, expressionSQL, orderList,
visibleColumnCount, distinct, filters);
visibleColumnCount, false, filters);
}
distinctColumnCount = expressions.size();
if (having != null) {
......
......@@ -99,6 +99,7 @@ public class TestScript extends TestDb {
testScript("testScript.sql");
testScript("comments.sql");
testScript("derived-column-names.sql");
testScript("distinct.sql");
testScript("dual.sql");
testScript("indexes.sql");
testScript("information_schema.sql");
......
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE TABLE TEST(ID BIGINT, NAME VARCHAR);
> ok
INSERT INTO TEST VALUES (1, 'a'), (2, 'B'), (3, 'c'), (1, 'a');
> update count: 4
CREATE TABLE TEST2(ID2 BIGINT);
> ok
INSERT INTO TEST2 VALUES (1), (2);
> update count: 2
SELECT DISTINCT ID FROM TEST ORDER BY NAME;
> ID
> --
> 2
> 1
> 3
> rows (ordered): 3
SELECT DISTINCT ID FROM TEST ORDER BY LOWER(NAME);
> ID
> --
> 1
> 2
> 3
> rows (ordered): 3
SELECT DISTINCT ID FROM TEST JOIN TEST2 ON ID = ID2 ORDER BY LOWER(NAME);
> ID
> --
> 1
> 2
> rows (ordered): 2
DROP TABLE TEST;
> ok
DROP TABLE TEST2;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论