0

I want to retrieve last inserted 'n' number of rows from an SQLite table. I used the below query but I'm getting error, please help me to correct my query. If my query is wrong please suggest me a better query:

public Cursor readLastNDetails(int n)
{
    return this.data.rawQuery("SELECT TOP ("+n+") Name,Place,occupation,Date from  tb_Employee order by id DESC", null);
}
Andriy M
  • 76,112
  • 17
  • 94
  • 154
Jesbin MJ
  • 3,219
  • 7
  • 23
  • 28

2 Answers2

2

Use following query,

"select Name,Place,occupation,Date 
 from  tb_Employee 
 order by id 
 desc limit"+ n
Sushil
  • 8,250
  • 3
  • 39
  • 71
Swati Sachdeva
  • 253
  • 2
  • 11
1

finally i got the answer

public Cursor readLastNYield(int n)
{
    return this.data.rawQuery("select BatchName,Yield,ActualYield,Date from tb_LabAssessment order by id DESC limit "+n, null);
}
Jesbin MJ
  • 3,219
  • 7
  • 23
  • 28