0

I am working to fetch the minimum value from a table in Grails where the vehicleid and the type is given

there are many values associated from that vehicleid and type i need to fetch the minimum date associated with that vehicleid . I have tried this but it is not working for the startDate param.

List vehicleDate= Table.createCriteria().list() {
   and{
      eq('vehicleid',vehicleIDGiven)
      eq('type',type)
      min("startDate")
   }
}

what could be the query like

Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
dhS
  • 3,739
  • 5
  • 26
  • 55

1 Answers1

1

If you just need to fetch the minimum value, you could use a projection as documented here.

Not tested, but your criteria should look something like this:

def result = Table.createCriteria().list() {
    and{
        eq('vehicleid',vehicleIDGiven)
        eq('type',type)
    }
    projections {
        min("startDate")
   }
}

println "Minimum start date is ${result[0]}"
aiolos
  • 4,637
  • 1
  • 23
  • 28