title: Unable to get the last inserted data from sqlite table
body: <p>In my application I need to get the data from the last inserted into table. What I have done is this</p>
  
  <pre><code> NSString *query  = [NSString stringWithFormat:@"SELECT * FROM PHONEBOOK ORDER BY NAME DESC LIMIT 1;"];
  
      //  NSLog(@"query : %@",query);
  
      BOOL recordExist = [self recordExistOrNot:query];
  
      if (!recordExist) {
  
          // save data if no record exists
      }
  
  
  
  
      -(BOOL)recordExistOrNot:(NSString *)query{
  
  BOOL recordExist=NO;
  
  sqlite3_stmt    *statement;
  const char *dbpath = [databasePath UTF8String];
  
  if (sqlite3_open(dbpath, &amp;myDatabase) == SQLITE_OK) {
  
  
  
  
      if (sqlite3_prepare_v2(myDatabase, [query UTF8String], -1, &amp;statement, nil)==SQLITE_OK)
      {
          if (sqlite3_step(statement)==SQLITE_ROW)
          {
              recordExist=YES;
  
              NSString *Name = [[NSString alloc]
                                   initWithUTF8String:
                                   (const char *) sqlite3_column_text(
                                                                      statement, 0)];
              NSString *PhoneNumber = [[NSString alloc]
                                       initWithUTF8String:
                                       (const char *) sqlite3_column_text(
                                                                          statement, 1)];
  
              //here i need to get the Name and number from the last inserted data
              NSLog(@"version is %@, type is %@",Name ,PhoneNumber);
          }
          else
          {
              NSLog(@"%s,",sqlite3_errmsg(myDatabase));
          }
          sqlite3_finalize(statement);
          sqlite3_close(myDatabase);
      }
  
  }
  return recordExist;
  </code></pre>
  
  <p>}</p>
  
  <p>The problem is I'm not getting the last inserted data. I am getting  the data from other rows ( i am not sure whether it is from top row or any other) . </p>
  
  <p>Could you please tell me what am I doing wrong here.</p>
  
  <p>Thanks in advance.</p>