tags:

views:

25

answers:

1

Hey there,

I would like to perform an SQLite query and order my results with numbers last.

Eg:

SQLite will ordinarily order results like this when I specify ASC on a text field:

0, 1, 2, A, B, C

Whereas I would like this:

A, B, C, 0, 1, 2

Any ideas? Is this possible?

Thanks!

Nick.

+1  A: 

I know nothing about sqllite, but something like this should work (assuming, of course, that there is some sort of isnumeric function available):-

order by isnumeric(colA), colA

so that your non-numerics appear first.

davek
A clever answer, I just tried it out and there doesn't appear to be an isnumeric function however. (SQL error: no such function: isnumeric). I'll take a look to see if it has a different name in SQLite.
Nick Cartwright
According to the docs, performing a mathematical operation on a non-numeric value results in null. Could you then use 'ISNULL(colA + 1) DESC' instead of 'isnumeric(colA)'?
davek
I checked that, and no luck... but on a bit of further Googling it seems IFNULL can be used also. 'order by IFNULL(colA + 1, 0), colA' seemed to do what I need! Thankyou for your help!!
Nick Cartwright