title: android sqlite group by clause
body: <p>i want to write a query to get last message send or receive to each contact. but unfortunalty group by clause is creating some issue like by writing the following query i get the last message that is send to a contact and if no message send to a contact then the last receive message is return by this query.</p>
  
  <pre><code>String where = "type=? OR type=? ) GROUP BY ( thread_id ";
      String[] whereArgs = new String[] { "" + Constants.SMS_RECEIVE,
              "" + Constants.SMS_SENT };
  
      try {
          Cursor cursor = ctx.getContentResolver().query(Constants.URI_SMS,
                  smsProjection, where, whereArgs, "date DESC");
  </code></pre>
  
  <p>and if i remove the group by clause i get all the messages send or receive to a contact.</p>
  
  <pre><code>    String where = "type=? OR type=? ";
      String[] whereArgs = new String[] { "" + Constants.SMS_RECEIVE,
              "" + Constants.SMS_SENT };
  
      try {
          Cursor cursor = ctx.getContentResolver().query(Constants.URI_SMS,
                  smsProjection, where, whereArgs, "date DESC");
  </code></pre>
  
  <p>the resone of using group by clause is that why fetch un related records from database.</p>