Name

reverse_unordered_selects — Reverse the order of unsorted query results

Common Usage

PRAGMA reverse_unordered_selects;
PRAGMA reverse_unordered_selects = switch;

Description

The reverse_unordered_selects pragma gets or sets the reverse select flag. If this flag is set, SQLite will reverse the natural ordering of SELECT statements that do not have an explicit ORDER BY clause.

SQLite, as well as the SQL standard, makes no promises about the ordering of SELECT results that do not have an explicit ORDER BY clause. Changes in the database (such as adding an index), or changes in the query optimizer can cause SQLite to return rows in a different order.

Unfortunately, writing application code that is dependent on the results order is a common mistake. This pragma can be used to help find and fix those types of bugs by altering the default output order. This can be especially effective if it is turned on or off randomly before each query.