Find max value in table column

Chopo87

New member
Hello

I am creating a version control domain class:

Code:
class VersionControl {

	Date dateCreated
	Long versionNumber

	Long getLatestVersionNumber() {
		//return largest versionNumber
	}

}

I would like to add a query to the largest version number stored:
Code:
Long getLatestVersionNumber()
. In SQL this query would look more or less as follows:
Code:
SELECT TOP 1 MAX(versionNumber) FROM VersionControl

The function MUST return the value as a long.

What is the correct way to do this in grails?

Thanks
 

dave

Administrator
Staff member
You can use criteria and a projection however probably the fastest method is simply to try :

VersionControl.executeQuery( 'select max(versionNumber) from VersionControl' )


 
Top