SQLite SELECT default order with PRIMARY KEY ASC

select, sqlite

Solution

There is no such thing as a default order, if you need your results ordered add an explicit order by clause.

The dbms is simply optimised to look for the best way to quickly get the required data based on the query. In this case it's the primary key on CN, but that's only because your example is so simple. Never ever rely on the dbms choosing the order you want.

Problem

I've created a SQLite table using: ``` CREATE TABLE T1 ( CN INTEGER PRIMARY KEY ASC, Name TEXT ); ``` If I do: ``` SELECT * FROM T1 ``` Will I get the rows order by CN even without specifying a ORDER BY clause? Is CN an alias to ROWID?

Original source