title: Ordering database records by timestamp - Oracle
body: <p>For the query:</p>
  
  <pre><code>SELECT MAX(LOG_CREATION_DATE),COL_A, COL_B
  FROM IMPORT_LOG
  GROUP BY TO_CHAR(LOG_CREATION_DATE, 'MM-DD-YYYY'),
                COL_A,
                COL_B
  ORDER BY  MAX(LOG_CREATION_DATE)  DESC
                ;
  </code></pre>
  
  <p>the records are in descending order as needed:</p>
  
  <pre><code>09-FEB-12 12.59.18.000000000 PM
  09-FEB-12 12.41.42.000000000 PM
  09-FEB-12 11.26.15.000000000 AM
  09-FEB-12 11.26.00.000000000 AM
  01-FEB-12 01.27.11.000000000 PM
  01-FEB-12 01.25.18.000000000 PM
  01-FEB-12 01.25.17.000000000 PM
  01-FEB-12 01.24.36.000000000 PM
  25-JAN-12 02.39.11.000000000 PM
  25-JAN-12 02.32.05.000000000 PM
  25-JAN-12 02.31.37.000000000 PM
  25-JAN-12 02.31.34.000000000 PM
  </code></pre>
  
  <p>But when I change the query to format the same timestamp column, the order completely changes to:</p>
  
  <pre><code>02-09-2012 12:02:18
  02-09-2012 12:02:42
  02-09-2012 11:02:15
  02-09-2012 11:02:00
  02-01-2012 01:02:11
  02-01-2012 01:02:18
  02-01-2012 01:02:17
  02-01-2012 01:02:36
  01-25-2012 02:01:11
  01-25-2012 02:01:05
  01-25-2012 02:01:37
  01-25-2012 02:01:34
  </code></pre>
  
  <p>the updated query is </p>
  
  <pre><code>SELECT TO_CHAR(MAX(LOG_CREATION_DATE), 'MM-DD-YYYY HH:MM:SS'),COL_A, COL_B
  FROM IMPORT_LOG
  GROUP BY TO_CHAR(LOG_CREATION_DATE, 'MM-DD-YYYY'),
                COL_A,
                COL_B
  ORDER BY  MAX(LOG_CREATION_DATE)  DESC
                ;
  </code></pre>
  
  <p>why is the output changed ?</p>