Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I insert data into SQLite table using "INSERT INTO.." statement
I read data from table using SELCT "FieldName" from "TableName" (that is without using ORDER BY)
=> Doubt is, whehter the read order will be same as insert order?? I expect the data in same order that is inserted?? Should i add an index field in table and use ORDER by for ensuring the order???


What I have tried:

When i tried usually get in the same order as that in which it is inserted? Will it always be like that?
Posted
Updated 19-Nov-18 22:31pm

1 solution

No, it doesn't have to be. The only way to be sure of an output order is to use an ORDER BY clause and reference a column that provides the order: an IDENTITY column, or a timestamp.

As you add and remove rows from yoru DB, it leaves "gaps" in the data, which can be filled later to prevent enlarging the file. This can reorder data, and an "implicit order" from your INSERT should never be relied upon. If you need a specific order, then always provide an ORDER BY clause.
 
Share this answer
 
Comments
dilsdgr8 21-Nov-18 2:39am    
In my case i am not deleting any entry. Only inserting. In this case, can I rely on the order
OriginalGriff 21-Nov-18 3:13am    
Not necessarily, no. You may not be deleting rows *yet*, but ...
If you want a specific order, always use ORDER BY.
dilsdgr8 21-Nov-18 4:47am    
Thanks..
my table cotains one field with large size binary data.. When i give order by, the memory used by application is increased drastically..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900