Hi!
SELECT MAX(id), userID FROM messages GROUP BY userID
Cursor cursor = daoSession.getDatabase().rawQuery("SELECT SUM(" + Company Dao.Properties.NumOfEmployees.columnName + ") FROM " + Company Dao.TABLENAME, new String []{});
cursor.moveToFirst();
long result = cursor.getLong(0);
Note that you could hardcode the column and table names above, but this is way cleaner.