First, you cannot rely on the order of the rows unless you specify it. So it is 
"just luck" that they are in ID order.

To get want you want you must specify an order and something like this will do 
what you want..

SELECT * FROM NEWFOLDER WHERE ID IN (3,1,2) ORDER BY FIELD (ID, 3, 1, 2);

So you need to put the same IDs in the FIELD as you have in the IN.

HTH

Andy Ling

-----Original Message-----
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Hegde, Deepakakumar (D.)
Sent: Fri 09 March 2018 13:15
To: sqlite-users@mailinglists.sqlite.org
Subject: [External] [sqlite] How to get the entry from sqlite db without 
primary key or rowid order?

This Message originated outside your organization.

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
---------------------------------------------------------------------------------------
This email has been scanned for email related threats and delivered safely by 
Mimecast.
For more information please visit http://www.mimecast.com
---------------------------------------------------------------------------------------

_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to