130
 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!

4 Answers 4

221

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" });   
Sign up to request clarification or add additional context in comments.

4 Comments

In my opinion, != looks more professional - and is more consistent with the = and == operators.
why I have to add "OR 'mycolumn' IS NOT NULL ? When I query with a where clause NOT EQUAL ?
@ban-geoengineering <> is SQL Ansi standard and != is not. Of course <> is more professional
@ban-geoengineering, here is a bunch of comments presenting arguments for usage of != or <>.
12

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

Comments

5

You can use <> operator

You will find here all the basic sql statements

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

2 Comments

Link is dead, consider updating it please
@v010dya Apologies for that. This was answered a long time ago, and I believe the article has been removed since then. As mentioned, you could use type<>? to solve the issue of inequality in an SQL query. Let me know if I can assist further by helping resolve your specific case study.
-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.