title: Selecting minimum date from postgres table using group by clause
body: <p>I have a table with data as company name, employee name, leave days. I want to extract the company name and min date for an employee. For this I am using this query </p>
  
  <pre><code>select companyname, min(date) from table where companyname = 'apple' and employeename = 'ABC'
  </code></pre>
  
  <p>This query however fails saying that column "tablename.companyname" must appear in the GROUP BY clause or be used in an aggregate function.</p>
  
  <p>I did try using companyname in group by clause along with date but this gave me a lot of values instead of one minimum date. </p>
  
  <p>Can any one figure out how to do this without adding to complexities.</p>
  
  <p>I did figure out the solution. However, I didn't quite understand why it asked me to use companyname in the group by clause. </p>