in mysql table i have the field 'date' which has the data as
2012-08-02 02:33:26
2012-08-02 05:33:26
2012-07-02 06:33:26
2012-06-02 01:33:26
2012-06-10 09:33:26
2011-05-10 10:33:26
2011-04-10 02:33:26
like that
i want to get the output as
2012-08
2012-07
2012-06
2011-05
2011-04
ie get the unique year and month (distinct of year and month of the date field)
I used the following query
SELECT distinct(YEAR(date)) FROM table
It returns the year only. i want to get the output as defined above. is there any possibility to get the out put like this. How do i write the select query.
Please help to this.
You might want to try this:
SELECT DISTINCT DATE_FORMAT(colName, '%Y-%m')
FROM tableName
SEE HERE: Date_Format( )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With