title: Fastest way to get minimum data from Database
body: <p>I have a <code>Postgres</code> database. I want to find the minimum value of a column called <code>calendarid</code>, which is of type integer and the format <code>yyyymmdd</code>,  from a certain table. I am able to do so via the following code. </p>
  
  <pre><code>get_history_startdate &lt;- function(src) {
    get_required_table(src) %&gt;% # This gives me the table tbl(src, "table_name")
      select(calendarid) %&gt;%
      as_data_frame %&gt;%
      collect() %&gt;%
      min() # Result : 20150131
  }
  </code></pre>
  
  <p>But this method is really slow as it loads all the data from the database to the memory. Any ideas how can I improve it? </p>