title: Room automatically sorts on the basis of primary key in Android
body: <p>I have a data class like this</p>
  
  <pre><code>@Entity
  data class Question(
  
          @field:SerializedName("question")
          var question: String? = null,
  
          @field:SerializedName("answers")
          var answers: ArrayList&lt;String?&gt;? = null,
  
          @field:SerializedName("id")
          @PrimaryKey
          var id: Int? = null
  )
  </code></pre>
  
  <p>Then in DAO I have saving and getting methods like this</p>
  
  <pre><code>    @Dao
  interface QnADao {
  
      @Insert(onConflict = OnConflictStrategy.REPLACE)
      fun saveQuestion(questions:Question)
  
      @Insert(onConflict = OnConflictStrategy.REPLACE)
      fun saveAllQuestions(questions: List&lt;Question?&gt;?)
  
  
      @Query("SELECT * from Question")
      fun getAllQnA():List&lt;Question&gt;
  
  
  }
  </code></pre>
  
  <p>I am saving a list of <code>Questions</code> and then later on retrieving them. So whenever I retrieve them I get the list sorted according to the <code>id</code> which is the primary key. </p>
  
  <p>So if I am saving questions with <code>id:254</code>, <code>id:23</code>, <code>id:45</code> and <code>id:92</code> then I am getting it like this <code>id:23</code>, <code>id:45</code>, <code>id:92</code> and <code>id:254</code></p>
  
  <p>But I don't need a sorted list like that, I need to get the data as it was saved in the database. Any help would be appreciated. Thanks.</p>