title: Select max data from row for every foreign key
body: <p>I have a MySQL Database, with some tables.</p>
  
  <p>With this query: </p>
  
  <pre><code>SELECT anagrafe.MARCHIO, anagrafe.BOLO, anagrafe.NUMERO_AZIENDALE, visite.COLLOCAZIONE, visite.DATA_PREVISTA_PARTO, visite.DATA_VISITA  
  FROM anagrafe LEFT JOIN visite USING(NUMERO_AZIENDALE) 
  WHERE visite.STATO_VISITA ='Gravida' AND visite.DATA_PREVISTA_PARTO &gt; '2017-04-01'
  </code></pre>
  
  <p>I get this:
  <a href="https://i.stack.imgur.com/umSSu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/umSSu.png" alt="enter image description here"></a>
  but I need only the row that have the max(DATA_VISITA) for every NUMERO_AZIENDALE (see the red)</p>
  
  <p>NUMERO_AZIENDALE is a foreign key for anagrafe (a table) and a part of primary key for visite (a table). 
  The primary key is composed by NUMERO_AZIENDALE and ID (not shown here)</p>
  
  <p>I tried with GROUP BY NUMERO_AZIENDALE but visite.COLLOCAZIONE is not shown properlly, that is, the query show the value of the row that I don't need</p>