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

AndroidSqlite

Android 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

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

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsammiweiView Question on Stackoverflow
Solution 1 - AndroidGraham BorlandView Answer on Stackoverflow
Solution 2 - AndroidAlpha75View Answer on Stackoverflow
Solution 3 - AndroidAmr AngryView Answer on Stackoverflow
Solution 4 - AndroidNoor HossainView Answer on Stackoverflow