hotkey
hotkey

Reputation: 148169

Is 'ORDER BY _id' enough to get rows in insertion order?

I'm using SQLite DB in my Android app. Now I need to implement data extraction in the same order in which it was inserted. Is it enough to do SELECT ... ORDER BY _id ... if the _id column is INTEGER PRIMARY KEY AUTOINCREMENT? Or should I add a column to store the date and time a row has been created?

Upvotes: 0

Views: 74

Answers (3)

Miguel A. Cardenete
Miguel A. Cardenete

Reputation: 122

You can use ORDER BY _id. Make sure you are using a List and not a Set....

Upvotes: 1

user1600401
user1600401

Reputation: 37

Yes, if you just need the order, you may use such statement or just simple "SELECT ... FROM sometable". Results will be equals.

Upvotes: 1

The Blue Dog
The Blue Dog

Reputation: 2475

No need, an id generated by AUTOINCREMENT is enough.

Upvotes: 1

Related Questions