Group Date Field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
DanielDrummond2k6
Forum Newbie
Posts: 2
Joined: Fri May 26, 2006 9:05 am

Group Date Field

Post by DanielDrummond2k6 »

Hi,

I necessary to create one query that it catches the field date of mysql and groups per years and months.

I go to explain better what I need:

I have that to create a list that only consists the months and the years of a table of news.

in this table I the same have some entrances of dates with different days of month, year.

Ex.

2006-01-01
2006-01-02
2006-01-03
2006-02-01
2006-02-02
2006-02-03
...

and i need to output only

2006-01
2006-02
....

Some one cam help-me...thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

An EXTRACT() call combined with GROUP BY or DISTINCT would work.

http://dev.mysql.com/doc/refman/4.1/en/ ... #id2920219
DanielDrummond2k6
Forum Newbie
Posts: 2
Joined: Fri May 26, 2006 9:05 am

Post by DanielDrummond2k6 »

SELECT date_format( Data, "%c-%Y" ) AS data_final
FROM `noticia`
GROUP BY data_final

heheheh

i find the anwser..
Post Reply