Strange exception when using groupBy in slick <p>I have a table with a few columns, two of them are: vendingMachineId (which are repeated) and each one has a timestamp.</p> <p>I want to get latest timestamp for each vendingMachineId so I did this:</p> <pre><code>def getLastReading(assetIds: List[Int])(implicit db: Session): Map[Int, String] = { val vmrps = (((for { vmrp &lt;- VendingMachineReadingProducts if (vmrp.vendingMachineId inSet assetIds) } yield (vmrp.vendingMachineId, vmrp.timestamp)).sortBy(_._2.desc)).groupBy(x =&gt; (x._1, x._2))).map { case (all, q) =&gt; all._1 -&gt; all._2 }.list vmrps map { case (assetId, timestamp) =&gt; { assetId -&gt; (new SimpleDateFormat(DateTimeUtils.defaultDateTimeFormat)).format(timestamp) } } toMap } </code></pre> <p>The issue is that I receive a strange exception:</p> <pre><code>scala.slick.SlickException: Unexpected node Ref @20339870 -- SQL prefix: select at scala.slick.driver.BasicStatementBuilderComponent$QueryBuilder.toComprehension(BasicStatementBuilderComponent.scala:75) ~[slick_2.10-1.0.0.jar:1.0.0] at scala.slick.driver.BasicStatementBuilderComponent$QueryBuilder.expr(BasicStatementBuilderComponent.scala:285) ~[slick_2.10-1.0.0.jar:1.0.0] at scala.slick.driver.PostgresDriver$QueryBuilder.expr(PostgresDriver.scala:55) ~[slick_2.10-1.0.0.jar:1.0.0] at scala.slick.driver.BasicStatementBuilderComponent$QueryBuilder.buildSelectPart(BasicStatementBuilderComponent.scala:155) ~[slick_2.10-1.0.0.jar:1.0.0] </code></pre> <p>Does anyone know what I am doing wrong?</p>