title: Android and SQLite - retrieve max id from table
body: <p>I am trying to create method to retrieve the max id from my table but I've problem.</p>
  
  <p>This is my method. It's working, but return value is 0,</p>
  
  <pre><code>public int getLastId() {
      openDB();
      int id = 0;
      final String MY_QUERY = "SELECT MAX(_id) AS _id FROM organize";
      Cursor mCursor = mDb.rawQuery(MY_QUERY, null);  
      try {
            if (mCursor.getCount() &gt; 0) {
              mCursor.moveToFirst();
              id = mCursor.getInt(mCursor.getColumnIndex(MY_QUERY));
            }
          } catch (Exception e) {
            System.out.println(e.getMessage());
          } finally {
              closeDB();
          }
  return id;
  
  }
  </code></pre>
  
  <p>can I fix this problem, thanks a lot</p>