Co Koder
Co Koder

Reputation: 2221

Android sqlite query

Cursor cursor = db.rawQuery("SELECT id,lastname FROM people WHERE lastname=null; ",null);

this query does not return the members whose lastname is empty. What is wrong with that query ? Should I check like that WHERE lastname="" ?

Upvotes: 0

Views: 170

Answers (2)

Alex Lockwood
Alex Lockwood

Reputation: 83303

It is not possible to test for NULL values with comparison operators, such as =, <, etc.

You have to use the IS NULL and IS NOT NULL operators instead.

SELECT id, lastname FROM people WHERE lastname IS NULL;

Upvotes: 1

Nick
Nick

Reputation: 6385

Try this instead:

    ... WHERE lastname IS NULL;

Upvotes: 5

Related Questions