如何用SLICK 3.2+编写SELECT子句中的嵌套查询 [英] How to write nested queries in select clause with slick 3.2 +
本文介绍了如何用SLICK 3.2+编写SELECT子句中的嵌套查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用SLICK 3.2+创建嵌套的SELECT? 基本上我需要在这里描述的内容How to write nested queries in select clause
但是,在SLICK 3.2上,此方法不起作用。
推荐答案
如果您有表Users
(id:uuid,电子邮件:字符串)和Persons
(用户名:uuid,名称:字符串,姓氏:字符串),则查询
select email
from Users
where id in (select userId
from Persons
where name = 'John'
and surname = 'Smith')
将类似于:
users
.filter(
_.id in persons
.filter(p => p.name === "John" && p.surname === "Smith")
.map(_.userId)
)
.map(_.email)
.result
您需要记住的事情:
Query
类型不是DBIO
(也不是DBIOAction
)-如果要编写查询,则需要在调用.result
之前编写.result
- 在条件中使用子查询时,请使用
in
而不是inSet
无论您使用in
、join
等,都应遵循相同的原则。
这篇关于如何用SLICK 3.2+编写SELECT子句中的嵌套查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文