从表中检索最后插入的'n'行

时间:2013-05-10 06:47:57

标签: android mysql sqlite android-sqlite

我想从SQLite表中检索最后插入的'n'行。我使用下面的查询,但我收到错误,请帮我纠正我的查询。如果我的查询错误,请向我建议一个更好的查询:

public Cursor readLastNDetails(int n)
{
    return this.data.rawQuery("SELECT TOP ("+n+") Name,Place,occupation,Date from  tb_Employee order by id DESC", null);
}

2 个答案:

答案 0 :(得分:2)

使用以下查询,

"select Name,Place,occupation,Date 
 from  tb_Employee 
 order by id 
 desc limit"+ n

答案 1 :(得分:1)

最后我得到了答案

public Cursor readLastNYield(int n)
{
    return this.data.rawQuery("select BatchName,Yield,ActualYield,Date from tb_LabAssessment order by id DESC limit "+n, null);
}