Consulting

Results 1 to 3 of 3

Thread: mysql qurey to order by month

  1. #1
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location

    mysql qurey to order by month

    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 the same

  2. #2
    VBAX Newbie
    Joined
    May 2009
    Posts
    3
    Location
    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
    [vba]SELECT column1, column2, MONTHNAME(column3)
    FROM TABLE
    ORDER BY column3[/vba]

  3. #3
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    i have used this query

    [VBA]
    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
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •