I have total 4 records in ecare table, where 2 records
status is sent = 1, and other 2 records status is sent = 0
RECORDS
1st Record : Track 1 [sent = 1]
2nd Record : Track 2 [sent = 1]
3rd Record : Track 3 [sent = 0]
4th Record : Track 4 [sent = 0]
But getting only last record (i.e. - Track 4) not all two records those status is sent = 0
Here is the SQLite query, which I am using to fetch data from database
public synchronized List<String> 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<String> records = new ArrayList<String>();
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
while (cursor.moveToNext()) {
records.add(cursor.getString(0));
}
return records;
}
UPDATED
public synchronized List<String> 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<String> records = new ArrayList<String>();
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;
}
Log says:
D/records:: [Getting only LAST record here] the 4th one
I guess, there is something wrong
with query, because I am getting only last record in Cursor
UPDATED RECORDS
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]
But getting only last record (i.e. - Track 5) not all three records those status is sent = 0
Log says:
D/records:: [Getting only LAST record here] the 5th one
UPDATED QUERY - Removed GROUP BY from query
And now getting each and every record, even those belongs to sent = 1 whereas I just want to fetch data that belongs to sent = 0 only
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' ";
See Question&Answers more detail:
os