SQLite Forum

UNION Sorts on First Field
If there is no ORDER BY clause, the SQL engine (*any* SQL engine, not just SQLite)
is free to return the rows in any order it wants.  That order might change from
one update of the database engine to the next, or from one database to the next,
or even on two consecutive runs of the same query.

If you need a particular output order, then you *must* use an ORDER BY clause.