statement ok
create table t(id int primary key, v1 int, v2 int)

statement ok
insert into t values(0, 1, 1), (1, 4, 2), (2, 3, 3), (3, 10, 12), (4, 2, 5)

query I
select v1 from t order by v1 asc
----
1
2
3
4
10

query I
select v1 from t order by v1 desc
----
10
4
3
2
1

statement ok
drop table t


statement ok
create table t(id int primary key, v1 int, v2 int)

statement ok
insert into t values (0, 1, 0), (1, 2, 2), (2, 3, 15), (3, 2, 12), (4, 3, 9), (5, 1, 5)

query II
select v1, v2 from t order by v1 asc, v2 desc
----
1 5
1 0
2 12
2 2
3 15
3 9

statement ok
drop table t

# sort with null
statement ok
create table t(id int primary key, v1 int null, v2 int null)

statement ok
insert into t values (0, 1, 0), (1, 2, 2), (2, null, 5), (3, 2, null), (4, null, null)

query II
select v1, v2 from t order by v1 asc, v2 asc
----
1 0
2 2
2 null
null 5
null null

query II
select v1, v2 from t order by v1 asc nulls last, v2 asc
----
1 0
2 2
2 null
null 5
null null

statement ok
drop table t

# sort on alias
statement ok
create table t(id int primary key, v1 int null, v2 int null)

statement ok
insert into t values(0, 1, 1), (1, 4, 2), (2, 3, 3), (3, 10, 12), (4, 2, 5)

query I
select v1 as a from t order by a
----
1
2
3
4
10

statement ok
drop table t