I want to simulate this query using kotlin exposed framework: I tried the next one query: But this query just results in: and the max value is selected in the code. How to perform finding max value on the side of the database and map it to Int? Answer I tried similar query and I believe it fits your need.