What is the syntax for "not equal" in SQLite?
AndroidSqliteAndroid Problem Overview
Cursor findNormalItems = db.query("items", columns, "type=?",
new String[] { "onSale" });
I want to return the cursor that points anything that are NOT onSale, what should I change? Thanks!
Android Solutions
Solution 1 - Android
From the official documentation:
> The non-equals operator can be either !=
or <>
So your code becomes:
Cursor findNormalItems = db.query("items", columns, "type != ?",
new String[] { "onSale" });
Solution 2 - Android
You should use in the comparator the non-equal operator:
"type!=?"
or "type<>?"
.
Solution 3 - Android
You can use <>
operator
You will find here all the basic sql
statements
Solution 4 - Android
With rawQuery :
quranCursor = db.rawQuery("SELECT * from alquran WHERE sura_id = '" + sooraId + "' AND ayat_id !='" + "0" + "'", null);
Usage:
int sooraId = 3 ;
try {
// start from not 0, but 1 ; Exclude All row with ayat_id = 0 :
quranCursor = db.rawQuery("SELECT * from alquran WHERE sura_id = '" + sooraId + "' AND ayat_id !='" + "0" + "'", null);
// or, quranCursor = db.rawQuery("SELECT * from alquran WHERE sura_id = '" + sooraId + "' AND ayat_id !='" + 0 + "'", null);
} catch (Exception e) {
e.printStackTrace();
}
This is tested one of my app, and works fine, Alhamdulillah.