Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get distinct months from database using HQL

I have a java.util.Date field in an @Entity and would like to get the distinct months from that column.

Suppose I only had three rows, with 14/07/2010, 24/11/1975 and 03/11/1975 (European date format - day/month/year), I would like to get the following back from Hibernate to go into a dropdown for filtering the data:

07/2010
11/1975

(or corresponding Date objects with the other fields set to zero - to be honest precisely how the data comes back isn't too important as I can work around that).

I'm guessing a database-agnostic approach in HQL isn't possible - any suggestions?

like image 850
Rich Avatar asked Sep 09 '10 05:09

Rich


1 Answers

What about :

select distinct month(c.birthday), year(d.birthday) from Cat c
like image 137
Pascal Thivent Avatar answered Oct 14 '22 00:10

Pascal Thivent