jeudi 26 février 2015

Android: SQLite GROUP BY

In my application, I have a database table containing chat messages,like below.



|---------------------------------------------|
|message | from | to |time
|-------------|-------|------|----------------|
|Hello |user1 |user2 |2015-2-26 1:15PM|
|-------------|-------|------|----------------|
|Watsup |user2 |user1 |2015-2-26 1:25PM|
|-------------|-------|------|----------------|
|Hows u? |user3 |user1 |2015-2-26 2:15PM|
|-------------|-------|------|----------------|
|Im fine |user1 |user3 |2015-2-26 2:35PM|
----------------------------------------------|


In my messages page I want list messages from all users. In this condition assume, "user1" as log-inned user,


Currently I am using query,



SELECT * FROM table GROUP BY from


and I am getting output as,



|--------------------------------|
|user2 |
|Hello |
|--------------------------------|
|user2 |
|Watsup |
|--------------------------------|
|user3 |
|Hows u? |
|--------------------------------|
|user3 |
|Im fine |
|--------------------------------|


What I want is distinct rows (like all chat apps),



|--------------------------------|
|user2 |
|Watsup |
|--------------------------------|
|user3 |
|Im fine |
|--------------------------------|


So, how can I write a sqlite query to fetch rows like this?


Aucun commentaire:

Enregistrer un commentaire