F. Böller
F. Böller

Reputation: 4294

Query one row with max value in one column in Slick

It seems to me like a simple problem, but I still try to find a good solution. I am using Slick 3.0. I want to query the row of a table, which has the highest value in one column. But I don't want to only have the highest value (this is simple), I want to have the whole row. I tried some things, like query first the max and then filter with this max value, but nothing compiled or looked appropiate. I would expect to be there a method like that:

table.maxBy(_.columnName)

But I didn't found a method like that. So what's the favorite way to do something like that?

Upvotes: 6

Views: 2333

Answers (1)

sap1ens
sap1ens

Reputation: 2957

The way to do it is to use this query:

table.sortBy(_.columnName).take(1).result

Unfortunately it produces SQL that is not optimized (but correct). Issue is reported and fixed, it'll be released in 3.1.0.

Upvotes: 6

Related Questions