-2

I have a query like this:

 Cursor _cursor = mbd.query(SQLITE_TABLE, new String[] {KEY_ROWID,
            KEY_SYLLABICATION, KEY_WORD, KEY_PARTOFSPEECH, KEY_MEANING, KEY_SPEAKWORD},
            null, null, null, null, null, null);

I just simply want to limit the rows to fetch from the database.

Jin
  • 162
  • 2
  • 14

2 Answers2

2

According to the documentation, you pass the LIMIT clause as the eighth parameter to query:

Cursor _cursor = mdb.query(SQLITE_TABLE,
                           new String[] { KEY_ROWID, KEY_SYLLABICATION,
                                          KEY_WORD, KEY_PARTOFSPEECH,
                                          KEY_MEANING, KEY_SPEAKWORD },
                           null, null, null, null, null,
                           "10");
CL.
  • 173,858
  • 17
  • 217
  • 259
1

Try this

cursor = resolver.query(STORAGE_URI, projection,
                        Media.BUCKET_DISPLAY_NAME + "=?",
                        new String[] { folderName },
                        " _id asc limit " + num);

or try this

final String orderBy = Constants.TABLE_CONVERSATION_FIELD_DATE + " DESC";
final String limit= 10;

return db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy, limit);
Yogesh Tatwal
  • 2,722
  • 20
  • 43