Android-SQLite select IS NOT NULL

I'm trying to get only data not NULL

in a database table, but the suggestion IS NOT NULL

doesn't work. Zero 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....
}

      

+3


source to share


1 answer


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



0


source







All Articles