title: SQL to select different records from a table based on different cases
body: <p>A table has data for trade deals. A trade deal (identified by deal_no) may have multiple records in the table.  However I want to select only one record. The condition to select one record depends on different cases. </p>
  
  <p>From the attached figure, I need to select the record with latest step_release_date, which is calculated as per below condition:</p>
  
  <pre><code>CASE
  WHEN (DEALSTP.IXSTP_OFFERING_DATE &gt; 0 ) THEN (DEALSTP.IXSTP_OFFERING_DATE)
  WHEN (DEALSTP.IXSTP_REL_DATE_A &gt; 0 ) THEN (DEALSTP.IXSTP_REL_DATE_A) 
  ELSE (DEALSTP.IXSTP_REL_DATE_B) 
  END ) as Step_release_date
  </code></pre>
  
  <p>How can I select the latest step_release_date from this table ?</p>
  
  <p><a href="https://i.stack.imgur.com/UpliO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UpliO.jpg" alt="enter image description here"></a></p>