For the query:
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
;
the records are in descending order as needed:
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
But when I change the query to format the same timestamp column, the order completely changes to:
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
the updated query is
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
;
why is the output changed ?
Your date format mask is wrong, you have the time part as
HH:MM:SSwhen you should haveHH:MI:SS. Or even better possibly,HH24:MI:SS.