Hello,
In my table I have a serial number field, which is represneted by string.. It has a prefix and some numbers follow. Eg: ABC1234, ABC2345 etc. How to retrieve the largest value (max equivalent of int type) from this column. In my case it would be ABC2345. I probably could retrieve all the data,, sort it and get the same, but that would be slow.
thanks in advance..
views:
33answers:
1
+1
A:
You need to utilize GORM criteria, projections in particular:
def c = MyEntity.createCriteria()
def maxNumber = c.get {
projections {
max("serialNumber")
}
}
This assumes that your entity is named MyEntity
and field is named serialNumber
.
Vladimir Grichina
2010-05-18 16:17:11