user103454
user103454

Reputation:

Parse year from SQL Date

I'm currently writing a Java app that interfaces with a MySQL database.
My problem is that I'm trying to write a function that fills a JComboBox with the unique year-values registered in the database.
I could use UNIQE on the date-field in the SQL query, but that would only exclude some of the dates, not all-but-one-date-per-year.
Any help would be greatly appreciated.

Upvotes: 0

Views: 581

Answers (2)

Nadia Alramli
Nadia Alramli

Reputation: 114971

Use the year function

Upvotes: 1

soulmerge
soulmerge

Reputation: 75724

SELECT DISTINCT YEAR(yourDateColumn) FROM yourTable;

Upvotes: 4

Related Questions