title: SQL - How to select/delete rows with the max value depending on two others
body: <p>I'm an intern in a property rental company. I'm in charge of developping the CRM under Symfony.</p>
  
  <p>So, ones of my entities are properties (houses) and their availabilities. See the table structure below.</p>
  
  <p><a href="https://i.stack.imgur.com/vexNZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vexNZ.png" alt="enter image description here"></a></p>
  
  <p>The problem I'm facing for now, is that the availabilities had been defined for each day (e.g. 28/01, 29/01, 30/01) instead of being defined for a range of day (e.g. 28/01 -> 30/01). So, the table is really heavy (~710 000 rows). Furthermore, before we changed the way of editing an availability, it created a new row for a same date instead of editing it. So, there are a lot of duplications in this table.</p>
  
  <p>What I want, is to lighten the DB by keeping only the rows which have the max value in <code>date_modif_availabilities</code> for the same <code>date_availabilities</code> and <code>id_properties</code>.</p>
  
  <p>For example, if I have these rows (availabilities_duplications):</p>
  
  <p><a href="https://i.stack.imgur.com/W9vhf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W9vhf.png" alt="enter image description here"></a></p>
  
  <p>I only want to keep the row with the latest modif like this (availabilities_keep_max_value) :</p>
  
  <p><a href="https://i.stack.imgur.com/3Prt5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Prt5.png" alt="enter image description here"></a></p>
  
  <p>The thing is, I don't know enough the SQL language. I'm able to write few basics scripts but not complex subqueries. Even with code samples that I found.</p>
  
  <p>Thank you in advance for your help.</p>