title: random sample of size N in Athena
body: <p>I'm trying to obtain a random sample of <code>N</code> rows from Athena. But since the table from which I want to draw this sample is huge the naive</p>
  
  <pre><code>SELECT
  id
  FROM mytable
  ORDER BY RANDOM()
  LIMIT 100
  </code></pre>
  
  <p>takes forever to run, presumably because the <code>ORDER BY</code> requires all data to be sent to a single node, which then shuffles and orders the data.</p>
  
  <p>I know about <a href="https://prestodb.io/docs/current/sql/select.html" rel="noreferrer"><code>TABLESAMPLE</code></a> but that allows one to sample some percentage of rows rather than some number of them. Is there a better way of doing this?</p>