1

I have a table with day column like this:

2011-04-28, 2011-04-29 ...
day           count  name surname
2011-04-28    8       titi tutu
2011-04-28     12     tutu toto
2011-04-27     2      tutu toto
2011-03-12     10     tutu toto

I can obtain distinct day but not only month and year.

select distinct(day) from Table where day between "2011-03-01" and "2011-04-28";

I want only distinct month and year.

Can you help me?

Thanks

Marc B
  • 356,200
  • 43
  • 426
  • 500
scraly
  • 11
  • 1

2 Answers2

2
select DISTINCT EXTRACT(YEAR_MONTH FROM `day`) as yearmonth
from Table
where day between '2011-03-01' and '2011-04-28';
Marc B
  • 356,200
  • 43
  • 426
  • 500
1

DISTINCT may be applied only to the whole row in mysql. So, you need to extract what you need first from the date.

select distinct(EXTRACT YEAR_MONTH FROM `day`) from Table 
      where day between "2011-03-01" and "2011-04-28";
Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156