My application has an sqlite DB, where some of the fields are null or empty (meaning that I never inserted anything into that field).
I wish to select all the records for which the field is null or empty.
This is what I have tried:
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, "folder_name = ? ", new String[] {"null"}, null, null, DBHelper.TIMESTAMP_COL + " DESC");
But that didn’t work, and I didn’t get any records. What do I need to do to make this work?
Try
cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, "folder_name is null or folder_name = ?", new String[] {""}, null, null, DBHelper.TIMESTAMP_COL + " DESC");
Answer:
db.rawQuery("SELECT * FROM myTable WHERE myColumn IS NULL", null);
Answer:
Just use “folder_name is null”
Answer:
I am using android studio 3.4,
Room 2.1.0-alpha07
This is my Kotlin Code
I tried using this didn’t work as expected
`@Query("SELECT *FROM notifications WHERE status=:status OR status = null")`
This one is working fine
@Query("SELECT *FROM notifications WHERE status=:status OR status is null")
Tags: androidandroid, select, sql, sqlite