title: SQLite Getting only last record not all the Records
body: <p>I have total <strong>4 records</strong> in <em>ecare</em> table, where <code>2 records</code> status is <strong>sent = 1</strong>, and other <em>2 records</em> status is <code>sent = 0</code></p>
  
  <p><strong>RECORDS</strong></p>
  
  <pre><code>1st Record : Track 1 [sent = 1]
  
  2nd Record : Track 2 [sent = 1]
  
  3rd Record : Track 3 [sent = 0]
  
  4th Record : Track 4 [sent = 0]
  </code></pre>
  
  <p>But getting only <em>last</em> record (i.e. - <strong>Track 4</strong>) not <em>all two</em> records those status is <strong>sent = 0</strong></p>
  
  <p>Here is the SQLite query, which I am using to fetch data from database</p>
  
  <pre><code>public synchronized List&lt;String&gt; getECareData() {
  
          String sql = "SELECT p.sent,e.*, e.no _id from ecare e LEFT JOIN pweb p ON e.h_id=p.h_id WHERE p.sent = '0' GROUP BY e.h_id";
  
          List&lt;String&gt; records = new ArrayList&lt;String&gt;();
          SQLiteDatabase db = this.getWritableDatabase();
          Cursor cursor = db.rawQuery(sql, null);
          while (cursor.moveToNext()) {
              records.add(cursor.getString(0));
          }
          return records;
      }
  </code></pre>
  
  <p><strong>UPDATED</strong></p>
  
  <pre><code> public synchronized List&lt;String&gt; getECareData() {
  
      String sql = "SELECT p.sent,e.*, e.no _id from ecare e LEFT JOIN pweb p ON e.h_id=p.h_id WHERE p.sent = '0' GROUP BY e.h_id";
  
      List&lt;String&gt; records = new ArrayList&lt;String&gt;();
      SQLiteDatabase db = this.getWritableDatabase();
      Cursor cursor = db.rawQuery(sql, null);
  
      // looping through all rows and adding to list
      if (cursor.moveToFirst()) {
          do {
              records.add(cursor.getString(0));
          } while (cursor.moveToNext());
      }
  
      Log.d("records:", records.toString());
  
      return records;
  }
  </code></pre>
  
  <p><strong>Log says:</strong></p>
  
  <pre><code>D/records:: [Getting only LAST record here] the 4th one
  </code></pre>
  
  <p>I guess, there is something <code>wrong</code> with <em>query</em>, because I am getting only last record in <strong>Cursor</strong></p>
  
  <p><strong>UPDATED RECORDS</strong></p>
  
  <pre><code>1st Record : Track 1 [sent = 1]
  
  2nd Record : Track 2 [sent = 1]
  
  3rd Record : Track 3 [sent = 0]
  
  4th Record : Track 4 [sent = 0]
  
  5th Record : Track 5 [sent = 0]
  </code></pre>
  
  <p>But getting only <em>last</em> record (i.e. - <strong>Track 5</strong>) not <em>all three</em> records those status is <strong>sent = 0</strong></p>
  
  <p><strong>Log says:</strong></p>
  
  <pre><code>D/records:: [Getting only LAST record here] the 5th one
  </code></pre>
  
  <p><strong>UPDATED QUERY</strong> - Removed GROUP BY from query</p>
  
  <p>And now getting each and every record, even those belongs to <strong>sent = 1</strong> whereas I just want to fetch data that belongs to <strong>sent = 0</strong> only </p>
  
  <pre><code>String sql = "SELECT p.sent,e.*, e.no _id from ecare e LEFT JOIN pweb p ON e.h_id=p.h_id WHERE p.sent = '0' ";
  </code></pre>