Home » SQL & PL/SQL » SQL & PL/SQL » Selecting a date part and ordering by date
Selecting a date part and ordering by date [message #23464] Wed, 11 December 2002 09:11 Go to next message
Chris
Messages: 128
Registered: November 1998
Senior Member
Hello everyone

I have hopefully a simple question. Right now I have a select which reads:

Select TO_CHAR(start_time,'Month') as available_months from someTable GROUP BY TO_CHAR(start_time,'Month')

This returns the correct data, which is a list of dates represented int he start_time column of someTable. The exact returned recordset is:

August
July
November
October
September

Problem is, they are sorted alphabetically rather than by date. How can i rework this select statement to return the months in correct date order? as in:

July
August
September
October
November

Thanks for your help
Re: Selecting a date part and ordering by date [message #23466 is a reply to message #23464] Wed, 11 December 2002 11:12 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
select d available_months 
  from (select to_char(start_time, 'Month') d 
          from t
         group by to_char(start_time, 'Month'))
 order by to_date(d, 'Month');
Re: Selecting a date part and ordering by date [message #23471 is a reply to message #23464] Wed, 11 December 2002 11:33 Go to previous messageGo to next message
casanova
Messages: 4
Registered: December 2002
Junior Member
try giving order by start_time at the end of sql statement.
Perfect! Thanks! nt [message #23472 is a reply to message #23464] Wed, 11 December 2002 11:57 Go to previous message
Chris
Messages: 128
Registered: November 1998
Senior Member
.
Previous Topic: :old :new
Next Topic: urgent!
Goto Forum:
  


Current Time: Wed May 15 11:20:16 CDT 2024