title: Comparing two dates and avoiding duplication
body: <p>I am working on HP ALM where i try to perform this query :</p>
  
  <pre><code>SELECT  ONE.ID, ONE.Num_QC_EDF, ONE.Statut, TWO.Proprietaire, ONE.ChangeDate
  FROM
  (SELECT B.BG_BUG_ID as ID, B.BG_USER_15 as Num_QC_EDF, AP.AP_NEW_VALUE as Statut, BG_RESPONSIBLE as Proprietaire, AL.AU_TIME as ChangeDate
  FROM  BUG B
  INNER JOIN AUDIT_LOG AL
  ON AL.AU_ENTITY_ID = B.BG_BUG_ID
  INNER JOIN AUDIT_PROPERTIES AP
  ON AL.AU_ACTION_ID = AP.AP_ACTION_ID
  AND AL.AU_ENTITY_TYPE = 'BUG'
  AND AL.AU_ACTION_ID= AP.AP_ACTION_ID
  AND AP_FIELD_NAME= 'BG_STATUS')ONE,
  (SELECT B.BG_BUG_ID as ID,B.BG_USER_15 as Num_QC_EDF, AP.AP_NEW_VALUE as Proprietaire , BG_STATUS as Statut , AL.AU_TIME as ChangeDate
  FROM  BUG B
  INNER JOIN AUDIT_LOG AL
  ON AL.AU_ENTITY_ID = B.BG_BUG_ID
  INNER JOIN AUDIT_PROPERTIES AP
  ON AL.AU_ACTION_ID = AP.AP_ACTION_ID
  AND AL.AU_ENTITY_TYPE = 'BUG'
  AND AL.AU_ACTION_ID= AP.AP_ACTION_ID
  AND AP.AP_FIELD_NAME = 'BG_RESPONSIBLE'
  AND B.BG_STATUS = 'TU leger OK')TWO,
  BUG B
  WHERE
  ONE.ID= TWO.ID AND ONE.Num_QC_EDF= TWO.Num_QC_EDF AND ONE.STATUT= TWO.STATUT and ONE.Proprietaire= TWO.Proprietaire and TWO.ChangeDate &lt;= ONE.ChangeDate
  Order by BG_BUG_ID, Num_QC_EDF, Proprietaire, ChangeDate
  </code></pre>
  
  <p>I would like to compare the ChangeDate situated in the second sub query to the one in the first sub query which must be  &lt;= ,also the whole query must'nt return duplicated rows in the result of it (PS: distinct doesn't work in nested queries) </p>
  
  <p>I am asking for help.</p>