Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SQLite select IS NOT NULL

I'm trying to retrieve only the data that are not NULL in a database table, but the IS NOT NULL clause does not seem to work. The null fields are also displayed.

String sql = "SELECT _id, nome_sotto FROM Categorie
 WHERE nome_categoria = '"+i.getStringExtra("categoria")+"' 
AND nome_sotto IS NOT NULL ORDER BY nome_sotto  ASC";

private void list() {
SQLiteDatabase db = mHelper.getReadableDatabase();
final List<Dettaglio> dettagli = new ArrayList<Dettaglio>();

String sql = "SELECT _id, nome_sotto FROM Categorie
 WHERE nome_categoria = '"+i.getStringExtra("categoria")+"' 
AND nome_sotto IS NOT NULL ORDER BY nome_sotto  ASC";

Cursor c = db.rawQuery(sql, null);

    while (c.moveToNext()){
        Dettaglio d = new Dettaglio();

        d.id = c.getString(0);
        d.sottocat = c.getString(1);                                

        dettagli.add(d);
    }
    c.close();


db.close();

ListAdapter adapter....
}
like image 776
user3608814 Avatar asked Apr 30 '26 18:04

user3608814


1 Answers

Empty is not the same as null. If you want to filter out empty values AND null values, you would need to add: AND nome_sotto != ''

like image 124
mikejonesguy Avatar answered May 02 '26 10:05

mikejonesguy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!