0

From my main.java:

 Cursor c = db.getDue(); String[] columns = new String[] { "_id", "date" }; int[] to = new int[] { R.id.num, R.id.date }; SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.lventer, c, columns, to); ListView lv1 = (ListView)findViewById(R.id.ListView01); lv1.setAdapter(mAdapter); 

From my database wrapper class:

 public Cursor getDue() { //String getdue = "SELECT * FROM tb1"; // this returns _id+date and displays them in the listview via the cursor adapter, defined above String getdue = "SELECT _id, max(date) AS date FROM tb1 GROUP BY _id";// this only works if I remove the "date" bindings defined above, only letting me see the _id, i want to see both _id and date in the lit view. return db.rawQuery(getdue,null); 

If I use the second select statment then it crashes unless I remove the "date" from the cursor adapter/listview bindings, if I do this then It will show the returned _id in the listview, but I want to see both _id and date in the listview.

I have been told that the second statment might returns a different type for date because of the max function ( I am not very sql literate, yet), but I thought that sqlite was loose with datatypes? Can anybody help, thanks in advance.

** UPDATE** This is the command that wont work with 2 columns fr the list view:

 SELECT _id, max(date) FROM jobs GROUP BY _id HAVING max(date) < (date-21) 

1 Answer 1

2

Use this:

String getdue = "SELECT _id, max(date) AS date FROM tb1 GROUP BY _id"; 
Sign up to request clarification or add additional context in comments.

4 Comments

sorry xandy I had pasted the incorrect query into the above code, please check for update.
I am guessing that the returned column from the query is not "date", but I dont know what it could be since I never constructed the query myself due to lack of sql knowledge, but I have a book ordered!
SQLite doesn't support Datetime data type. Please refer to this: sqlite.org/datatype3.html#datetime
Problem may be coming from (date-21), it depends on your declaration of your field, (date-21) should not be understood by the system (or at least not what you would expected).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.