If the prefered ORDER BY clause is awkward;
How large is your table?
 and is it on a Solid State Disk (SSD) with low seek time?

If the table is small (less than 100,000 rows) and you are querying by an
indexed field (such as the Primary Key)
you could just do three (or N) SELECT statements to guarantee the order.

SELECT * FROM NEWFOLDER WHERE ID = 3;
SELECT * FROM NEWFOLDER WHERE ID = 1;
SELECT * FROM NEWFOLDER WHERE ID = 2;

This is NOT efficient, but it is what transaction processing systems do all
day with randomly arriving known customers.

If you need the results combined in one data structure (for all the values
of ID) you could make this more elaborate with a UNION query
or you could assemble the data in the language that you are calling SQL
from (assuming you are not using the command line interface). If you are
using the command line interface you could redirect to a file and append
(">" and ">>").

Jim Callahan
Callahan Data Science LLC
Orlando, FL

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#m_-7888910753152976491_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Fri, Mar 9, 2018 at 8:14 AM, Hegde, Deepakakumar (D.) <
deep...@allgosystems.com> wrote:

> Hi All,
>
>
> We have a problem as below:
>
>
> we have created a table as below:
>
> CREATE TABLE NEWFOLDER(ID INTEGER PRIMARY KEY, NAME TEXT NOT NULL) ;
>
> We have inserted 5 entry to this table, and ID will be from 1 to 5 as below
>
> ID   NAME
> 1     ABC
>
> 2     AAA
>
> 3     CBA
>
> 4     BAC
>
> 5     BBB
>
>
> We execute following select statetment:
>
>
> SELECT * FROM NEWFOLDER WHERE ID IN (3,1,2);
>
>
> output for above is:
>
>
> ID   NAME
>
> 1     ABC
>
> 2     AAA
>
> 3     CBA
>
>
> It seems by default sqlite is getting the entry in the order of primary
> key or rowid.
>
>
> So for us expected output is:
>
> ID   NAME
>
> 3     CBA
>
> 1     ABC
>
> 2     AAA
>
>
> Is there anyway to do this without adding a new column? with the same
> table?
>
> we need a way where by we can get the entry as we given in "where" "in"
> clause
>
>
> Thanks and Regards
>
> Deepak
>
>
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to