What is the syntax for "not equal" in SQLite?

 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!

105404 次浏览

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" });

You should use in the comparator the non-equal operator: "type!=?" or "type<>?".

You can use <> operator

You will find here all the basic sql statements

http://www.firstsql.com/tutor2.htm

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 ; Include All row but ayat_id = 0 :
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.