Sort null data in a database query

I have an application in which I order a request to my database with the ORDER BY clause, he will order them in alphabetical order. I have only one small problem, quite often it happens that one of the lines that the order orders does not contain anything (string = ") when sorting in alphabetical order, they are filled at the top of the list infront om a, b, c ... I am simple and simple, I don’t want it. after I googling a lot on the oracle forum that I have to change the part of the SORT BY request to the request "SORT BY xxx ASC NULLS LAST", this caused a fatal error in the request.

How can I fix this seemingly small problem?

here is my request like today.

public Cursor fetchAllDatesByTag() { return mdiktationsDb.rawQuery("SELECT " + KEY_DATEID + "," +" " + KEY_DATE + "," + " " + KEY_TIME + "," + " " + KEY_DICTTAG + "," + " " + KEY_DICTLISTIMAGE + " FROM " + DATABASE_TABLE + " ORDER BY " + KEY_DICTTAG + " ASC", null); }

+3
source share
3

CASE ORDER BY

ORDER BY CASE column WHEN NULL THEN 1 ELSE 0 END, column

, .

EDIT: "s" ( ) - , ... .

EDIT2:

....+ " ORDER BY CASE " + KEY_DICTTAG + "WHEN NULL THEN 1 ELSE 0 END, " + KEY_DICTTAG + " ASC"
+8

:

ORDER BY foo NULLS LAST

ORDER BY foo NULLS FIRST

: (

:

ORDER BY IF(ISNULL(my_field),1,0),my_field

"" -, 0 1, , my_field null, . , , . SQL my_field, .

+1

WHERE NOT NOT. , .

0

Source: https://habr.com/ru/post/1783958/


All Articles