title: Select the last row in a SQL table
body: <p>Is it possible to return the last row of a table in MS SQL Server.
  I am using an auto increment field for the ID and i want to get the last one just added to join it with something else. Any idea?</p>
  
  <p>Here's the code:</p>
  
  <pre><code>const string QUERY = @"INSERT INTO Questions (ID, Question, Answer, CategoryID, Permission) " 
                     + @"VALUES (@ID, @Question, @Answer, @CategoryID, @Permission) "; 
  
  using (var cmd = new SqlCommand(QUERY, conn)) 
  { 
      cmd.Parameters.AddWithValue("@Question", question); 
      cmd.Parameters.AddWithValue("@Answer", answer); 
      cmd.Parameters.AddWithValue("@CategoryID", lastEdited);
      cmd.Parameters.AddWithValue("@Permission", categoryID);
      cmd.ExecuteNonQuery(); 
  }
  </code></pre>