How to use IN clause in Slick? How to use IN clause in Slick? mysql mysql

How to use IN clause in Slick?


You can do this with the method .inSet (see here):

Slick

Slick queries are composable. Subqueries can be simply composed, where the types work out, just like any other Scala code.

val address_ids = addresses.filter(_.city === "New York City").map(_.id)people.filter(_.id in address_ids).result // <- run as one query

The method .in expects a sub query. For an in-memory Scala collection, the method .inSet can be used instead.

So that would mean for your code:

val nameFilter= List("Sachin","Naveen")val filteredQuery = query.filter(_.name.inSet(nameFilter))var result= dbHandle.db.run((filteredQuery.drop(10).take(10)).result

Depending on the source of that input you should consider using .inSetBind to escape the input (see this SO post).