Is there any way to create nested select using slick 3.2+ ? Basically all that I need described here How to write nested queries in select clause
However on slick 3.2 this approach does not work.
Is there any way to create nested select using slick 3.2+ ? Basically all that I need described here How to write nested queries in select clause
However on slick 3.2 this approach does not work.
If you have tables Users (id: UUID, email: String) and Persons (userId: UUID, name: String, surname: String) than query
select email
from Users
where id in (select userId
from Persons
where name = 'John'
and surname = 'Smith')
would look kind of like:
users
.filter(
_.id in persons
.filter(p => p.name === "John" && p.surname === "Smith")
.map(_.userId)
)
.map(_.email)
.result
Things you need to remember:
Query type is not DBIO (nor DBIOAction) - if you want to compose queries, you need to do it before calling .result on themin instead of inSetSame principle should hold whether you use in, join, etc.
( tableA.map(a => (a.id, a.2)) join tableB.map(b.id, b.1) on (_._1 === _._1) ).map(_._4). Alternatively, just use sql"""query""".