nano_nano
nano_nano

Reputation: 12523

SQLite Count(column) GROUP BY issue

I cannot figure out the following problem. I am get a very simple table with a name column. Now I want to count all the names inside this relation with the functionality below.

Cursor c = database.rawQuery(
            "select count(name) from geo group by name", null);
    int count = 0;
    if (c.getCount() > 0) {
        c.moveToFirst();
        count = c.getInt(0);        
    }
    c.close();
    return count;

I see exactly two rows in my table. One with name "John" the other with name "Sandra". But the code return always count = 1 If I execute the sql in my serverside application with mysql it runs fine.

Do you see the problem?

Upvotes: 1

Views: 1726

Answers (1)

podiluska
podiluska

Reputation: 51494

You probably want

 SELECT count(name) FROM geo

or

 SELECT count(DISTINCT name) FROM geo

Upvotes: 4

Related Questions