PDA

View Full Version : mysql qurey to order by month



shamsam1
01-19-2010, 04:28 AM
i have a table where i am storing all the months where its in varchar january,december,march,july,june, etc

i want mysl qurey to order by month

ex
january
febuary,
march

kindly guide me in doing:dunno the same

shorty
01-24-2010, 06:54 AM
Change the column with the months, (which is now a varchar) into a date column.
Let's take for example a 3 column table, colum3 is your month column, then your query would be
SELECT column1, column2, MONTHNAME(column3)
FROM TABLE
ORDER BY column3

shamsam1
01-25-2010, 12:56 AM
i have used this query


SELECT *,
(CASE
WHEN month= 'January' THEN 0
WHEN month= 'Febuary' THEN 1
WHEN month= 'march' THEN 2

END) as rank
FROM text ORDER BY rank