title: aggregate functions are not allowed in WHERE
body: <p>I am using this query to find the unique records by latest date using postgresql. The error I am having is "aggregate functions are not allowed in WHERE". <a href="https://stackoverflow.com/questions/41277189/how-to-fix-error-aggregate-functions-are-not-allowed-in-where">How to fix error “aggregate functions are not allowed in WHERE”</a> Following this link I have tried to use inner select function. But this did not work. Please help me to edit the query. I am using PgAdmin III as client.</p>
  
  <pre><code>SELECT Distinct t1.pa_serial_
      ,t1.homeownerm_name
      ,t1.districtvdc
      ,t1.date as firstrancheinspection_date
      ,t1.status
      ,t1.name_of_data_collector
      ,t1.fulcrum_id
      ,first_tranche_inspection_v2_reporting_questionnaire.date_reporting
  From first_tranche_inspection_v2 t1
  LEFT JOIN first_tranche_inspection_v2_reporting_questionnaire ON (t1.fulcrum_id = first_tranche_inspection_v2_reporting_questionnaire.fulcrum_parent_id)
  where first_tranche_inspection_v2_reporting_questionnaire.date_reporting = (
          select Max(first_tranche_inspection_v2_reporting_questionnaire.date_reporting)
          from first_tranche_inspection_v2
          where first_tranche_inspection_v2.pa_serial_ = t1.pa_serial_
          );
  </code></pre>