My question is about how get the max id row of a table... I'm using max function but give me a error

Here is my code

     public static long getLastIdQuotaAdded(Context context){
    long id;
    Cursor cursor;
    String selection = null;
    String[] selectionArgs = null;

    selection = "MAX(" + C_ID + ")";

    cursor=context.getContentResolver().query(URI, ALL_COLUMNS, selection, selectionArgs, null);
    id = cursor.getLong(cursor.getColumnIndex(C_ID));
    return id;

Thank you for yout help... :)


Your query (even the part that is visible) is not valid SQL.

To get the maximum value of a specific column, use something like this:

SELECT MAX(_id) FROM mytable;

In SQLite, if your ID is the Row ID (see the documentation), you can just do:

SELECT last_insert_rowid();

there is a table named sqlite_sequence in SQLITE that is used to store the auto_increment_key.

this is the query to get latest auto_increment_key values.

Cursor cursor = db.rawQuery("SELECT seq FROM sqlite_sequence WHERE name=?",
                new String[] { TABLE_NAME });
int last = (cursor.moveToFirst() ? cursor.getInt(0) : 0);

Need Your Help

How to save non property values in iOS using NSUserDefaults?

iphone ios ipad cocoa-touch nscoding

I am saving the AccessToken that I got from one Social Networking website.when I save this then I come to know that We can't directly save the non property values in iOS SDK.

In Sublime Text, how do I find and replace the file name

linux unix sublimetext2

Is there a way in sublime text where I can find a pattern and replace it with file names.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.