kashipai / h2database

H2 Database for reference.
0 stars 0 forks source link

Order by on multiple columns with limit behaviour #451

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Is it normal that the output varies when using multiple ordering columns and 
the order of those columns are varied?

For instance:

create table test_table (
        id int8 not null,
        year int4 not null,
        province varchar(16) not null,
        dangerous bool,
        sector varchar(9) not null,
        unit varchar(3) not null,
        amount numeric not null
    );

insert into test_table (id, year, province, dangerous, sector, unit, amount) 
values (1, 2012, 'W_FL', true, 'FOTOG', 'TNE', 55);
insert into test_table (id, year, province, dangerous, sector, unit, amount) 
values (2, 2012, 'E_FL', true, 'CHEM', 'TNE', 54);
insert into test_table (id, year, province, dangerous, sector, unit, amount) 
values (3, 2012, 'W_FL', true, 'CHEM', 'TNE', 74);
insert into test_table (id, year, province, dangerous, sector, unit, amount) 
values (4, 2012, 'E_FL', true, 'FOTOG', 'TNE', 4);
insert into test_table (id, year, province, dangerous, sector, unit, amount) 
values (5, 2012, 'LIM', true, 'FOTOG', 'TNE', 4);

First query:
------------
select
        * 
    from
        test_table test 
    where
        test.year=2012
    order by
        test.province asc,
        test.sector asc
 limit 2;

Which outputs:
ID      YEAR    PROVINCE    DANGEROUS   SECTOR      UNIT    AMOUNT  
2   2012    E_FL        TRUE        CHEM        TNE 54
4   2012    E_FL        TRUE        FOTOG       TNE 4

Second query:
-------------
select
        * 
    from
        test_table test 
    where
        test.year=2012
    order by
    test.sector asc,
        test.province asc
 limit 2;

This query returns something else:
ID      YEAR    PROVINCE    DANGEROUS   SECTOR      UNIT    AMOUNT 
2   2012    E_FL        TRUE        CHEM        TNE 54
3   2012    W_FL        TRUE        CHEM        TNE 74

It is as if only the second order by clause is used by the limit...

Original issue reported on code.google.com by jan.liev...@gmail.com on 21 Mar 2013 at 1:44

GoogleCodeExporter commented 9 years ago
Please use the Google Group or StackOverflow first, and only submit issues if 
you are completely, 100% sure it is an issue.

Original comment by thomas.t...@gmail.com on 21 Mar 2013 at 1:50

GoogleCodeExporter commented 9 years ago
Indeed this not a bug

Original comment by jan.liev...@gmail.com on 21 Mar 2013 at 3:01