title: Oracle SQL: getting only one max row using multiple criteria
body: <p>I have this table:</p>
  
  <pre><code>Department   NAME   EMAIL         ID     DATE1         DATE2
  1            John   asd@asd.com   74     05/04/2007    05/04/2007
  1            Sam    asd@asd.com   23     05/04/2007    05/04/2007
  1            Tom    asd@asd.com   46     05/04/2007    03/04/2007
  1            Bob    bob@asd.com   23     01/01/2006
  2            Tom    asd@asd.com   62     02/02/2000    05/05/1997
  </code></pre>
  
  <p>I want to get the row (only one per department) with max <code>DATE1</code>, but it's not unique! So if there is multiple results I want to get the max <code>DATE2</code>, and if there are multiple ones then the one with the biggest ID is returned.</p>
  
  <p>So there result of the query would be:</p>
  
  <pre><code>1            John   asd@asd.com   74     05/04/2007    05/04/2007
  2            Tom    asd@asd.com   62     02/02/2000    05/05/1997
  </code></pre>
  
  <p>Thank you very much.</p>