Tonious
Tonious

Reputation: 53

Sqlite query check - less than and greater than

return mDb.query(DATABASE_TABLE, new String[] { KEY_ROWID, 
KEY_LEVEL }, KEY_LEVEL + ">" + "=" + 3 + "<" + 5, null, null, null, null);

What am I doing wrong. It's returning all over above and equal to level 3 but not less than 5. I've tried && | and such.

Upvotes: 3

Views: 5291

Answers (2)

Guillaume
Guillaume

Reputation: 22822

KEY_LEVEL + ">" + "=" + 3 + "<" + 5

translates as

KEY_LEVEL + ">=3<5"

Use that instead:

KEY_LEVEL + ">= 3 AND " + KEY_LEVEL + " < 5"

Upvotes: 8

Brian Kyckelhahn
Brian Kyckelhahn

Reputation: 342

Compare KEY_LEVEL to 3 and compare KEY_LEVEL to 5 with a conjunction of two expressions. I've never seen SQL use the && or || operators; use AND and OR.

Upvotes: 1

Related Questions