0

For example, this user did it like this in MySQL:

Ordering by the order of values in a SQL IN() clause

But I wish to do something just like that in sqlite3. Is it possible? I can't seem to get the ORDER BY FIELD part working, and I did some looking up and found that maybe it's because SQLite3 does not have this "ORDER BY FIELD" Functionality?

I'm trying to make something like this work:

SELECT observationKey  
   FROM observation 
  WHERE observationKey IN ( 1, 2, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 3, 4, 5, 6, 7...) 
 ORDER BY FIELD (observationKey , ( 1, 2, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 3, 4, 5, 6, 7...))

*I added ellipses at the ends of the list for this example to indicate it can go on to a lot of numbers.

This list of observationKeys can be infinitely large and in a specific order which is detrimental to getting things working how they should in my program.

Anyone know how to get the result set to come out in the order in which I asked for it? Currently, with no ORDER BY being used, they come out in what ever order they want from time to time. It's random. I need it to stop being random.

Community
  • 1
  • 1
Ryval
  • 13
  • 2
  • 7

0 Answers0