title: Hibernate: how to select last N rows in ascending order of id? (in single query)
body: <p>Hibernate version: 5.2</p>
  
  <p>I am trying to use subqueries to do, and use setMaxResults(int).</p>
  
  <pre><code>session.createQuery(
  "FROM ( SELECT * FROM tickets ORDER BY id DESC limit 3) sub ORDER BY id ASC"
  );
  </code></pre>
  
  <p>However, HQL subqueries can occur only in the select or where clauses, and limit can't be used in hibernate.</p>
  
  <p>How can I do it in hibernate?</p>
  
  <hr>
  
  <p>Update - To make it clear</p>
  
  <p>For eg, there are 10 data entries from id=1 to id=10.</p>
  
  <p>I want to select last 3 data in ascending order of id by <strong>only one query</strong> + <strong>without further data processing</strong>.</p>
  
  <p>The result from db would be id=8 to id=10</p>
  
  <p>Thank You.</p>