Sqlite: Order By 'insertorderindb'
Solution 1:
SQLite tables have a "secret" column called ROWID
the value of which increases as you add rows. It can serve as a proxy for "order entered into table". ROWID
is basically a "free" auto-incrementing integer primary key column for the table.
Note that by definition SQL databases have no notion of row ordering. While I would be surprised if the behavior of ROWID
every changed in SQLite (since it's existence and behavior is documented), as a rule if you want to retrieve rows in an ordered fashion in SQL databases you're responsible for storing the ordering information yourself.
Solution 2:
Solution 3:
The best-practices method of sorting rows by the temporal order in which they have been inserted is to use a timestamp column which is assigned as a default value the date-time corresponding to "now", as the row is being inserted. This is easy to do in SQLite.
Post a Comment for "Sqlite: Order By 'insertorderindb'"