SQLite Forum

Is the order conserved in a table from a VALUES clause?
Login
Well, in the current impl, the `values` clause is *special* it seems,  
since `PRAGMA reverse_unordered_selects` does not affect it (see below).

But the fact remains that `values` is table-like, and represents a **set** of rows,  
not a list.  So it's entirely conceivable for SQLite to internally sort them,  
or heap-sort them, or leave them as-is, or randomize them.

Just don't really on any implicit or *lexical* order. Always use an explicit order.  
For example:
`
sqlite> with t(ord, val) as (values (1, 'two'), (2, 'one'), (3, 'five')) select val from t order by ord;
two
one
five
`


```
C:\Users\ddevienne>sqlite3
SQLite version 3.28.0 2019-04-16 19:49:53
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> create table t (v int);
sqlite> insert into t(v) values (1), (2), (3);
sqlite> select * from t;
1
2
3
sqlite> select * from (values (1), (2), (3));
1
2
3
sqlite> PRAGMA reverse_unordered_selects;
0
sqlite> PRAGMA reverse_unordered_selects = 1;
sqlite> PRAGMA reverse_unordered_selects;
1
sqlite> select * from t;
3
2
1
sqlite> select * from (values (1), (2), (3));
1
2
3
sqlite> select * from (values (1), (2), (3)) order by 1;
1
2
3
sqlite>
```