来自 Slick 文档:http ://slick.typesafe.com/doc/1.0.0/lifted-embedding.html#joining-and-zipping ,以下是 Slick 中的一些可能连接以及与之相关的一些粗略 SQL
val implicitCrossJoin = for {
c <- Coffees
s <- Suppliers
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c, Suppliers s
val implicitInnerJoin = for {
c <- Coffees
s <- Suppliers if c.supID === s.id
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c, Suppliers s where c.supID = s.id
val explicitCrossJoin = for {
(c, s) <- Coffees innerJoin Suppliers
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c CROSS JOIN Suppliers s
val explicitInnerJoin = for {
(c, s) <- Coffees innerJoin Suppliers on (_.supID === _.id)
} yield (c.name, s.name)
//SELECT c.name, s.name FROM Coffees c INNER JOIN Suppliers s ON (c.supID = s.id)
val explicitLeftOuterJoin = for {
(c, s) <- Coffees leftJoin Suppliers on (_.supID === _.id)
} yield (c.name, s.name.?)
//SELECT c.name, s.name FROM Coffees c LEFT OUTER JOIN Suppliers s ON (c.supID = s.id)
val explicitRightOuterJoin = for {
(c, s) <- Coffees rightJoin Suppliers on (_.supID === _.id)
} yield (c.name.?, s.name)
//SELECT c.name, s.name FROM Coffees c RIGHT OUTER JOIN Suppliers s ON (c.supID = s.id)
val explicitFullOuterJoin = for {
(c, s) <- Coffees outerJoin Suppliers on (_.supID === _.id)
} yield (c.name.?, s.name.?)
//SELECT c.name, s.name FROM Coffees c FULL OUTER JOIN Suppliers s ON (c.supID = s.id)
如您所见,大多数构造都非常直接地映射到 SQL。
希望有帮助