Works for me. ``` sqlite> create table x(x); sqlite> insert into x select value from wholenumber where value between 1 and 10; sqlite> create table y(x,y); sqlite> insert into y select value, RandomV(10) from wholenumber where value between 1 and 10; sqlite> select * from x; ┌────┐ │ x │ ├────┤ │ 1 │ │ 2 │ │ 3 │ │ 4 │ │ 5 │ │ 6 │ │ 7 │ │ 8 │ │ 9 │ │ 10 │ └────┘ sqlite> select * from y; ┌────┬───┐ │ x │ y │ ├────┼───┤ │ 1 │ 1 │ │ 2 │ 9 │ │ 3 │ 0 │ │ 4 │ 0 │ │ 5 │ 3 │ │ 6 │ 9 │ │ 7 │ 9 │ │ 8 │ 0 │ │ 9 │ 5 │ │ 10 │ 6 │ └────┴───┘ sqlite> select x from (select x, (select y from y where x.x == y.x) from x order by 2); ┌────┐ │ x │ ├────┤ │ 3 │ │ 4 │ │ 8 │ │ 1 │ │ 5 │ │ 9 │ │ 10 │ │ 2 │ │ 6 │ │ 7 │ └────┘ sqlite> select x from x order by (select y from y where y.x == x.x); ┌────┐ │ x │ ├────┤ │ 3 │ │ 4 │ │ 8 │ │ 1 │ │ 5 │ │ 9 │ │ 10 │ │ 2 │ │ 6 │ │ 7 │ └────┘ sqlite> select x.x from x join y on x.x == y.x order by y.y; ┌────┐ │ x │ ├────┤ │ 3 │ │ 4 │ │ 8 │ │ 1 │ │ 5 │ │ 9 │ │ 10 │ │ 2 │ │ 6 │ │ 7 │ └────┘ sqlite> ``` NB: wholenumber is the wholenumber virtual table add-in NBB: RandomV is a custom add-in that returns a random integer Edited to add a join candidate sort