I have a data in my db, like:
2016-05-17 , 2015-05-20 , 2015-02-02
I want to get only the years to create a list, like:
2016 , 2015
I'm making this:
SELECT * FROM insercao GROUP BY SUBSTR(data,0,4)
But this return only:
2015
How can I return All not duplicated years?
If data
is a datetime field, you ahve to change your query in this way:
SELECT * FROM insercao GROUP BY YEAR(`data`)
In fact, to return only year value, you have to act in this way:
SELECT YEAR(`time`) as year FROM insercao GROUP BY year
select distinct EXTRACT(YEAR FROM date_column_name) FROM date_extract;
The extract keyword of MYSQL extracts years form the date format that you mentioned in question.
Distinct will only select non repeating years.