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....
}
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 != ''
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With