I have couple of columns in the table in Oracle DB, one is of varchar2 type while other is of date. I want to retrieve distinct ordered data
The following is the output of the below query
select CS_ID,CS_Date from CSM order by CS_Date;
which yields:
CS_ID CS_Date
CS0000000001 29/03/15 14:23:25.872000000
CS0000000001 29/03/15 14:23:30.546000000
CS0000000001 29/03/15 14:23:30.577000000
CS0000000001 29/03/15 14:24:54.331000000
CS0000000001 29/03/15 14:39:51.881000000
CS0000000001 29/03/15 14:44:18.306000000
CS0000000001 29/03/15 14:44:27.372000000
CS0000000002 29/03/15 15:38:40.657000000
CS0000000003 29/03/15 18:41:15.409000000
CS0000000004 29/03/15 19:31:45.614000000
After adding distinct, following is the output. Ordered is not maintained after adding distinct
select distinct CS_ID from (
select CS_ID,CS_Date from CSM order by CS_Date
) v
which yields:
CS_ID
CS0000000002
CS0000000004
CS0000000003
CS0000000001
I am expecting the following output
CS_ID
CS0000000001
CS0000000002
CS0000000003
CS0000000004
Could you please advise to how to maintain the order with distinct clause?