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
  • 73,804
  • 16
  • 91
  • 150
Jesbin MJ
  • 3,049
  • 6
  • 22
  • 27

2 Answers2

2

Use following query,

"select Name,Place,occupation,Date 
 from  tb_Employee 
 order by id 
 desc limit"+ n
Sushil
  • 7,865
  • 2
  • 35
  • 66
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,049
  • 6
  • 22
  • 27