|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Arranging mysql data
hi i have a table which has a field called month whose values are
January,February,March etc in no particular order i am selecting all daya from this table and the month values are in the following order: January November December February March April May June July August September October i want it to be displayed in the proper order January February March .. .. .. December Can some1 please help me with this. Thanks in advance Suk |
|
#2
|
||||
|
||||
|
Code:
ORDER
BY POSITION( LEFT(monthname,3)
IN 'JanFebMarAprMayJunJulAugSepOctNovDec' )
|
|
#3
|
|||
|
|||
|
You could also do something like this:
Code:
SELECT monthname
FROM monthnames
ORDER
BY STR_TO_DATE(monthname,'%M');
|
|
#4
|
||||
|
||||
|
Quote:
Code:
SELECT monthname
, STR_TO_DATE(monthname,'%M') as m
FROM monthnames
;
monthname m
January 0000-01-00
November 0000-11-00
December 0000-12-00
February 0000-02-00
March 0000-03-00
April 0000-04-00
May 0000-05-00
June 0000-06-00
July 0000-07-00
August 0000-08-00
September 0000-09-00
October 0000-10-00
![]() |
|
#5
|
||||
|
||||
|
The ideal situation would be to store the month as an INT and do the translation to long name during the query or application execution. If it is part of a multiple-field storage of date information it would be best to simply consolidate to a single DATE type and extract the relevant data with the appropriate functions.
|
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Arranging mysql data |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|