I'm trying to sort monthname and year in a descending order. The date column in the table is as follows
orderdate
----------
2020-12-15
2021-01-15
2021-02-15
2021-02-20
2021-03-21
2021-03-29
2021-04-15
The expected results is
monthName
-----------
April 2021
March 2021
February 2021
January 2021
December 2020
I tried this query
select distinct to_char(orderdate::date,'FMMonth YYYY') as monthName from table
order by to_char(orderdate::date,'FMMonth YYYY') desc;
The above query gives me the output as
monthName
-----------
March 2021
January 2021
February 2021
December 2020
April 2021
How do I get the expected output from the query.