2

I'm new to SQLite. I'm using this query in order to extract all rows from a column for a specific user:

        Cursor c = db.query(true, TABLE, COLUMN, USER + "= '" + user + "'", null, null, null, null, null);

This is an example of table:

|group-----ID|
|------------|
|one-------me|
|one------you|
|two-------me|
|one-------me|

So the query for user "me" extracts "one, two, one". How can I filter the result in order to obtain a value just one time? Like "one, two"

Thanks

1 Answer 1

5

Use the Group By parameter with the appropriate column name:

Cursor c = db.query(true, TABLE, COLUMN, USER + "= '" + user + "'", null,
            "group", null, null, null);

Since there are nine parameters in this method and three nearly identical methods...

public Cursor query(boolean distinct, 
                    String table, 
                    String[] columns, 
                    String selection, 
                    String[] selectionArgs, 
                    String groupBy,          /* this one */
                    String having, 
                    String orderBy, 
                    String limit)
Sign up to request clarification or add additional context in comments.

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.