title: What is the difference between df.select() and df.agg()?
body: <p>I have a dataframe from which I want to extract Maximum value, Minimum value and Count the number of records in it.</p>
  
  <p>The dataframe is:</p>
  
  <pre><code>scala&gt; val df = spark.range(10000)
  df: org.apache.spark.sql.Dataset[Long] = [id: bigint]
  </code></pre>
  
  <p>For getting the required values I am using <code>df.select()</code>, like this:</p>
  
  <pre><code>scala&gt; df.select(min("id"), max("id"), count("id")).show
  +-------+-------+---------+
  |min(id)|max(id)|count(id)|
  +-------+-------+---------+
  |      0|   9999|    10000|
  +-------+-------+---------+
  </code></pre>
  
  <p>Which gives me correct results, but when I tried <code>df.agg()</code> it also gave me same answer.</p>
  
  <pre><code>scala&gt; df.agg(min("id"), max("id"), count("id")).show
  +-------+-------+---------+
  |min(id)|max(id)|count(id)|
  +-------+-------+---------+
  |      0|   9999|    10000|
  +-------+-------+---------+
  </code></pre>
  
  <p>So, my question is what is the difference between <code>df.select()</code> and <code>df.agg()</code> if they provide the same results and which one should I use for better performance ?</p>