GET表的最大ID行 [英] GET MAX ID ROW OF A TABLE

查看:212
本文介绍了GET表的最大ID行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于如何得到一个表的最大ID行......我使用最多的功能,但给我一个错误

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

下面是我的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;
}

感谢您对YOUT帮助...:)

Thank you for yout help... :)

推荐答案

您查询(甚至是可见的部分)是不是有效的SQL。

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;

在SQLite的,如果你的ID是的的行ID(请参见的文档),你可以做:

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

SELECT last_insert_rowid();

这篇关于GET表的最大ID行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆